问题
i want to add drag and drop support to my JTree application
i hav a created a custom DefaultMutableTreeNode subclass
hav a default TreeCellRenderer
what all things do i need to add and where?
回答1:
The easiest way is to
1. Call tree.setDragEnabled(true)
2. set tree.transferHandler
There's a tutorial at: http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
You create a subclass of TransferHandler where you implement
canImport(JComponent comp, DataFlavor[] transferFlavors)
and
importData(JComponent comp, Transferable t)
回答2:
I found this also useful
https://blogs.oracle.com/CoreJavaTechTips/entry/adding_drop_support_to_jtree
来源:https://stackoverflow.com/questions/1526291/adding-drag-and-drop-support-to-jtree