Is there a good way to track drags with a mouse listener? Or does anyone here understand how dnd (drag-and-drop) works with JTree? I'm stuck on converting a DefaultMutableTreeNode into a MIME string that I can use with DataFlavor. Ideally, I'd like to be able to have the dnd be done in my application rather than using JTree's (for undo/redo implemented by my application), but I've read from quite a few sources that doing so now is impractical, and it's best to implement a TransferHandler.
I'm using a basic JTree object with:
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); this.tree.setAutoscrolls(true); this.tree.setDragEnabled(true); this.tree.setDropMode(DropMode.ON_OR_INSERT); this.setTransferHandler(new TestTransferHandler());
It also has a bunch of nodes that all extend from DefaultMutableTreeNode. It is possible to select multiple nodes that are not next to each other. The TestTransferHandler class is really nothing more than a class that extends TransferHandler (I haven't figured out which methods I need to override, and with what). Also, do I need to have my custom node objects implement Transferable? If so, how would/should I go about this?