Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming the JTree Node Manually in Java

Tags:

java

swing

jtree

I have created a jtree with the root node "RootNode" and some other nodes like "Node1","Node2", Node3".

After creation of tree I want to rename the rootnode or any other node by manually. We can rename the node dynamically by using the method

 jtee.setEditable(true);

But I want to change the name in manualy by the code level

like

 someMethod(Arg1 oldNodeName,Arg2 newNodeName)

Is there any way to do this?

like image 345
Sathish Avatar asked Feb 24 '23 14:02

Sathish


1 Answers

Assuming you are using a DefaultMutableTreeNode you could just change the UserObject (whose toString() method is what is used to display the node name) by calling: setUserObject() on the node you want to change.

like image 176
jzd Avatar answered Mar 06 '23 21:03

jzd