开发者

make a duplicate node in Jtree

开发者 https://www.devze.com 2023-02-17 07:19 出处:网络
i want to make a duplicate node in Jtree but the code is not working inside mouse action listener....

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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消