amit singh
amit singh

Reputation: 1

make a duplicate node in Jtree

i want to make a duplicate node in Jtree but the code is not working inside mouse action listener....

/* DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
      def obj = selectedNode.getUserObject()
      DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)node.getRoot().getChildAt(0);
      model.insertNodeInto(selectedNode, parentNode, 0)*/

Upvotes: 0

Views: 1249

Answers (2)

Bombe
Bombe

Reputation: 83853

You are not making a copy, you just try to insert the (existing) node into a different location.

DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
def obj = selectedNode.getUserObject()
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)node.getRoot().getChildAt(0);
model.insertNodeInto(new DefaultMutableTreeNode(obj), parentNode, 0);

(Obvious syntax errors have not been corrected, I am not your compiler.)

Upvotes: 1

duffymo
duffymo

Reputation: 308753

I don't see a call to "new" anywhere in this code. Did I miss it? Wouldn't that be a requirement or creating a new Node?

Create a new DMTN and initialize it with the state of the one you want to copy.

Upvotes: 1

Related Questions