This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Create JTree using data from Map

 
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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?
 
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.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic