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 = (D开发者_如何转开发efaultMutableTreeNode)node.getRoot().getChildAt(0);
model.insertNodeInto(selectedNode, parentNode, 0)*/
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.
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.)
精彩评论