JTreeTable DnD crazy flashing cursor

I am using a slightly modified version of the Sun example JTreeTable, supported by my own model. This will be the third example (bookmarks at http://java.sun.com/products/jfc/tsc/articles/bookmarks/ ).

Everything works as expected, except for drag and drop support. I need DnD, which is more like what it provides JTree. Because it JTreeTableis extended JTable, it provides a class JTable.DropLocationfor determining drag locations that does not provide enough information when dropping material into a column processed by a tree JTreeTable(without path and without child index). I already solved this by creating my own DropLocationclass based on a combination of JTableand versions JTree. I also changed the paint method of the class TreeTableCellRenderer, which is provided by the mentioned implementationJTreeTableto show this new information to the user (now she can see whether the new node will be placed inside, before or after the selected node, if inside the tree column, as expected from JTree).

However, there is one problem. The mouse cursor goes crazy when the cropping place is displayed inside a tree column. It appears and then disappears a few milliseconds later, or it happens so quickly that the drag cursor does not even appear. This also happens with Sun's unmodified example. I am completely in the dark why this is happening. Find another person with the same problem at http://www.java.net/node/663106 , but the solution provided there seems to be where the component removal location was null and could not be restored using the method JTreeTable.getDropLocation(). I need this to convert it to modifiedDropLocationand then draw on it. I am so close to the right solution for my use case that I can try it. This cursor is blinking, this is the only obstacle in my way. Any ideas?

Using Java 1.6.

PS: I decided to use custom JTreeTable, and not for one of the existing components (for example, Netbeans Outline or JXTreeTable), since they all seem to suffer from the problem JTable.DropLocationand do not offer support for deleting before or after the selected node tree (only inside). If you know about a component that provides such functionality, I would be glad to hear about it.

+5
source share
1 answer

# 6700748 ( , darn bug parade , ..), , 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 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));
    }
+7

All Articles