Hi everyone, i have the question, which i'v already a few days not solved.
I built a tree just like the sample "Dynamically Changing a Tree" on "http://download-llnw.oracle.com/javase/tutorial/uiswing/components/tree.html".
After inserting or removing nodes in(from) the tree, i close the whole window, when i open the widow another time, the new inserted (or removed) node are all gone. so the question is, how can i restore my new done nodes in the right path, so that after the tree window new opening, i can see the new tree structure?
any help appreciated!!
posted 6 years ago
You are asking how to have your data persist, and so I must ask if you write anything to disk after you've made your changes, or when a "Save" button or menu has been pressed? And, do you read in this saved data when the program starts or on the press of some button or menu? If not, you'll want to check out the same tutorial's IO section.
When changing the content of your tree you have to save it to a file or database. Best is to have a data model following the composite pattern (Composite Pattern) that can naturally displayed as a tree. In this case you might want to create your own TreeModel (TreeModel) and pass your object holding the tree data to the TreeModel.
grapes are vegan food pellets. Eat this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user