Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

restoring and recalling a JTree  RSS feed

 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!