Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

restoring and recalling a JTree

 
sindy lee
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Luck.
 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!