TreeEditor: Customizing Drag and Drop
JTree is a Java GUI component for tree structure. The tree structure is represented by nodes ( DefaultMutableTreeNode ). The path or the placement of the node in the tree is represented by TreePath . DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); Use TransferHandler for drag and drop. Supposing a class derived from TransferHandler called MenuTransferHandler handles drag and drop, set the TransferHandler as follows: MenuTransferHandler handler = new MenuTransferHandler(); treeEditor . tree .setTransferHandler(handler); The copied new node should be generated at TransferHandler#createTransferable() . Here shows the function copy() that may come in handy in writing createTransferable() . copy() should be called recursively. private DefaultMutableTreeNode copy (TreeNode node) { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node); if (!node.isLea...