• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree - Making it editable

 
Sanjit Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am displaying an XML file in a JTree. I would like the user to be able to click on the nodes and change its name. It would be nice if after removing the focus from the changed node, the changes are automatically saved in the xml file.
I have no idea how to implement this and any insights from an experienced person would be very helpful.
Regards,
Sanjit
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This depends how you set up your Nodes that are used by your Tree/TreeModel.
Probably the simplest way is to override valueForPathChanged in your tree model.
E.g. create a class that extends DefaultTreeModel. Override valueForPathChanged so that it changes the underlying data objects. Either there, or from your data objects (preferrably), invoke your model saving method.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic