I haven't looked closely at Mr. Wood's code, but if you can presume jdk 1.4 or better, I think it would probably be easier to use the TransferHandler class.
JTree myTree = new JTree(...);
JTable myTable = new JTable(...);
myTree.setTransferHandler(...); // pass a handler for the drag-out
myTable.setTransferHandler(...); // pass a handler for the drop-into
It's that easy. Ok, not really because you have to actually write the TransferHandlers, but it's not so bad. It's easier to comprehend than the DragGesture/DropTarget stuff, and Sun does provide some
examples.
a few notes, because I'm oh so helpful:
1) If you can presume 1.6 or better, you probably want to call myTable.
setDropMode() for better drop feedback.
2) If it might be run on 1.5, you probably want to set the
sun.swing.enableImprovedDragGesture system property.
[edit: I've had trouble with this on Macs, in that it made dropping impossible. So either set sun.swing.enableImprovedDragGesture only on non-Macs, or
test well.]
3) If you want to convey Java objects within the same JVM and you don't want your objects to be silently serialized and deserialized, set the MIME type of your Transferable to something like
DataFlavor.javaJVMLocalObjectMimeType+";class=the.fully.qualified.ClassName". The Sun tutorial linked above mentions this, but it's easy to miss.
[ December 14, 2006: Message edited by: Brian Cole ]