Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTree - Saving Changes

Status
Not open for further replies.

chris921

Technical User
Mar 9, 2004
82
GB
Hiya,

Just wondering if theres a method that allows you to save changes to a JTree - such that the changes will be still there following closing of the file and reloading?

Thanks,

Chris
 
There is quite a lot of scope to that question. It depends on the application. If the JTree is displaying information from some database, then changes in the tree structure should naturally be persisted back to the database. Ditto for a file.

However, you may want to persist the tree model as a serialised object. You could persist a DefaultTreeModel as a serialised object (as a binary object file or XML file, check out java.beans.XMLEncoder and XMLDecoder). It depends on what you're trying to achieve.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
i've created a tree which displays basic elements that the user can delete as well as add new elements to the tree.
 
Chris921, the tree is only a means of displaying/manipulating data. Your most recent post is merely stating the obvious. Deciding how to persist the information depends upon other things:-
1) How much data are we talking about?
2) Does the data need long-term storage or not?
3) Is there any other data (not part of the tree) which belongs in the problem space?
4) Is the application purely a 'stand-alone' app or one which many users on a network will use?
5) Will many users want to access the same data?
... and so on.

In other words, yes we could provide a concrete example of how you would persist the data in your tree, but without details from you it may not be an appropriate approach.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top