File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTree - Making it editable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree - Making it editable" Watch "JTree - Making it editable" New topic

JTree - Making it editable

Sanjit Singh

Joined: Nov 12, 2001
Posts: 27
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.
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
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.
I agree. Here's the link:
subject: JTree - Making it editable
It's not a secret anymore!