pre*_*edi 6 java swing drag-and-drop cursor jtreetable
我正在使用JTreeTable由我自己的模型支持的Sun示例的略微修改版本.这将是第三个例子(http://java.sun.com/products/jfc/tsc/articles/bookmarks/上的书签).
除拖放支持外,一切都按预期工作.我想DnD更像是JTree提供的东西.由于JTreeTable是扩展,JTable它提供了JTable.DropLocation用于确定丢弃位置的类,当将内容放入JTreeTable(无路径和无子索引)的树呈现列时,该类不提供足够的信息.我已经通过创建一个DropLocation基于它的组合JTable和JTree版本的自定义类来解决这个问题.我还修改了TreeTableCellRenderer由上述JTreeTable实现提供的类的paint方法,以向用户显示此新信息(她现在能够查看新节点是否将放置在所选节点内部,之前或之后,如果在内部树列,正如您所期望的那样a JTree).
但是有一个问题.当在树列内呈现放置位置时,鼠标光标会变得疯狂.它出现然后在几毫秒后消失,或者这种情况发生得如此之快,甚至没有显示拖动光标.这也发生在未经修改的Sun的例子中.我完全不知道为什么会这样.在http://www.java.net/node/663106找到了另一个有同样问题的人,但是那里提供的解决方案似乎将组件的放置位置设置为null,并且无法再使用JTreeTable.getDropLocation()方法检索.我需要这个将它转换为我的修改DropLocation然后根据它绘制的东西.我非常接近我的用例的正确解决方案,我可以品尝它.这个光标闪烁的东西是我的唯一障碍.有任何想法吗?
使用Java 1.6.
PS:我已经决定使用自定义JTreeTable而不是现有组件之一(如Netbeans Outline或者JXTreeTable),因为它们似乎都遇到了JTable.DropLocation问题,并且不支持在所选树节点之前或之后删除(仅在内部) ).如果你知道一个提供这种功能的组件,我会很高兴听到它.
kle*_*tra 10
这听起来像是一个核心bug #6700748的表现(无法验证,这个darn bug游行需要很长时间才能连接到...).因此引用JXTreeTable中的修复:
/**
* {@inheritDoc} <p>
*
* Overridden to hack around #766-swingx: cursor flickering in DnD
* when dragging over tree column. This is a core bug (#6700748) related
* to painting the rendering component on a CellRendererPane. A trick
* around is to let this return false. <p>
*
* This implementation applies the trick, that is returns false always.
* The hack can be disabled by setting the treeTable's client property
* DROP_HACK_FLAG_KEY to Boolean.FALSE.
*
*/
@Override
public boolean isVisible() {
return shouldApplyDropHack() ? false : super.isVisible();
}
/**
* Returns a boolean indicating whether the drop hack should be applied.
*
* @return a boolean indicating whether the drop hack should be applied.
*/
protected boolean shouldApplyDropHack() {
return !Boolean.FALSE.equals(treeTable.getClientProperty(DROP_HACK_FLAG_KEY));
}
Run Code Online (Sandbox Code Playgroud)