• Post Reply Bookmark Topic Watch Topic
  • New Topic

Renaming JTree nodes

 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a tree here where nodes are objects. How I can make a feature that allows user to rename those objects without getting any exceptions? Now it is basically something like this: user doubleclicks a node and then it is editable but after pressed enter and name changed and altered node is selected again, an exception occurs :|
I need to have update statement but where? Now I have these lines:
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a TreeModel? The model controls the data (= the nodes) and handles changes and propagates the changes to the view (= JTree). If you are extendending DefaultTreeModel, the listener algorithm is already implemented. you just need to fire an appropriate event if something changes.
Have you had a look at the swing tutorial for JTree and TreeModel?
cheers
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, that was a bit way off?! certainly your using a TreeModel!
you have to call yourTreeModel.nodeChanged(theNode) after you made some change to a treenode. (This method is in DefaultTreeModel, you should rather extend this one than just implement TreeModel.)
I hope this was more help!
 
Martin Schneider
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was so simply I didn't get it
All I have to do was to add a method that changes the name of object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!