3

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?

  • Possible duplicate of [Drag and Drop nodes in JTree](http://stackoverflow.com/questions/4588109/drag-and-drop-nodes-in-jtree) – Suma Dec 01 '15 at 12:29

2 Answers2

8

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) 
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77
1

I found this also useful

https://blogs.oracle.com/CoreJavaTechTips/entry/adding_drop_support_to_jtree

drzymala
  • 2,009
  • 20
  • 26