Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Data Structure for display in JTree?  RSS feed

 
Nina Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, There,
I need to recursively call SQL to retrieve data which have inhert relationships. Then display the data into JTree. I don't need the tree to be balanced or ordered, but definitely not binary.
And the JTree need to be manipulated a lot while keeping the hierarchy of the tree.
Does anyone have recommendation on what Data Structure I should use to store the data returned from Database? Or should I just write my own tree structure?
Thanks a lot!!
Nina
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a lot with JTrees and at least for me it was enough to extend form DefaultTreeModel and to fill the model with DefaultMutableTreeNodes. The DefaultMutableTreeNode has an UserObject. There you can put in any Object, you need. It should simply implement a toString method for displaying. I think, this is the reason, why DefaultMutableTreeNodes are a good choice.
 
Nina Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rene!
Because I need to display the tree first. Then allow people to select leaves into a list, although the list is a flat one, I still need to keep the integrity of the original tree structure within the list by validating the leaves every time people choose them.
Have you ever done this kind of things? Do you think the treeModel is enough to do that? Thanks!
Nina
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!