• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create JTree using data from Map  RSS feed

 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initialy I am creating a JTree with the data obtained from model. While creating the tree, I store the node information in a Map.
Later,I am trying to create a JTree using the data from Map which was populated while creating the tree initially. but, since the parent-child relationship is already set up, the tree is not getting created.
It just show the root node (root is shown because I am doing -> rootNode.setUserObject(data)). When I get the next avlue from Map and do insert(), it does not show up on the tree.
Can some one please tell me how to create tree from the tree data stored in Map? Not able to figure out for the past 2 days.

Thanks.
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one please help me on this.
Thanks.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not clear on how the tree data is set up in the Map... A Map has keys and entries, what type of data are in the keys? What type of data are in the entries? Maps are also un-ordered, so how do you know where the data goes in the tree?
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that you want to convert the tree to a map to store it and reuse it later. Why aren't you using Serialization for this? That is it's purpose. You would have to create an ObjectOutputStream, serialize the tree (store it on disc), and whenever you need it, you would create an ObjectInputStream and deserialize it.
see:
http://java.sun.com/docs/books/tutorial/essential/io/serialization.html
Chantal
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for he reply. I was able to solve the problem myself.
I was storing the node id as key and the node itself as the value in Map.
To recreate the tree I used temporary Map along with the original Map key-values.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!