Adding drag and drop support in Jtree

I want to add drag and drop support in a JTree application

i hav created a custom subclass of DefaultMutableTreeNode

hav default TreeCellRenderer

What do I need to add and where?

+3
source share
2 answers

The easiest way is 1. Call tree.setDragEnabled (true)
 2. set tree.transferHandler

There tutorial: 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) 
+8
source

Source: https://habr.com/ru/post/1719402/


All Articles