aspose file tools*
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
Author

JTree - Making it editable

Sanjit Singh
Greenhorn

Joined: Nov 12, 2001
Posts: 27
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

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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree - Making it editable