Reputation: 479
Could anyone help me allow a DataFlavor from one tree into the other? I have been following a few tutorials, and have a drag and drop working within the two trees, however I would like to be able to drag between them.
This is the part that is throwing the exception, within my overridden importData method;
try {
Transferable t = support.getTransferable();
nodes = (MyNode[])t.getTransferData(nodesFlavor);
} catch(UnsupportedFlavorException ufe) {
System.out.println("UnsupportedFlavor: " + ufe.getMessage());
} catch(java.io.IOException ioe) {
System.out.println("I/O error: " + ioe.getMessage());
}
The exception thrown is;
UnsupportedFlavor: application/x-java-jvm-local-objectref
Any help would be greatly appreciated.
Cheers,
Shaun
Upvotes: 0
Views: 317
Reputation: 6229
You need to implement a custom TransferHandler
. From the java tutorial,
List, table, and tree do not support drop by default. The reason for this is that there is no all-purpose way to handle a drop on these components. ... While Swing cannot provide a default implementation for these components, the framework for drop is there. You need only to provide a custom TransferHandler that manages the actual import of data."
If you are exporting just the names of the tree nodes as strings, this should be pretty easy. See the rest of that tutorial for info on how to do this. If you are trying to export an object, you will need to create your own Transferable
implementation too.
Upvotes: 1