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?
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.