Home arrow static arrow Java Programming [Archive] - tree formed from database
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - tree formed from database
This topic has 5 replies on 1 page.

Posts:18
Registered: 1/12/04
tree formed from database  
Aug 2, 2004 3:33 AM



 
I have a table of values stored similar to this,

BaseNumber         Name            UniqueNumber  null               Parent                11                  Child                 21                  OtherChild            32                  grandchild            4

In the above table a 'null' value in BaseNumber signifies that an entry has no 'parent'. 'Child' has a BaseNumber of '1', meaning that it is the child of the entity with UniqueNumber '1'. This data grows dynamically, and it might be expected to consist of up to 3000 entries.

My problem is that i want to display this information visually as a tree of sorts. There is an example of the sort of tree display i am looking for shown in the jdsk folder, but, having browsed the code and almost understood it, i can't see how to enter the children under the correct parent. From what i can see the example i have been looking at places its child nodes randomly instead of specifiying what values go where.

Can anyone help?
yours,
Michael
 

Posts:12,831
Registered: 2/22/00
Re: tree formed from database  
Aug 2, 2004 5:09 AM (reply 1 of 5)



 
Are you asking how to turn that data into a tree data structure, or, having already done that, how to display it in a way that represents the tree?

If the latter, have you looked at Swing JTree?
 

Posts:13,250
Registered: 24/10/97
Re: tree formed from database  
Aug 2, 2004 6:03 AM (reply 2 of 5)



 
There was a thread in the Algorithms forum (http://forum.java.sun.com/thread.jsp?forum=426&thread=532391) that dealt with a similar problem to this. The difference I see is that you want to load from a database rather than a flat file but the main part of the problem is the same.
 

Posts:18
Registered: 1/12/04
Re: tree formed from database  
Aug 2, 2004 9:53 AM (reply 3 of 5)



 
The link you gave pointed to a binary tree, but the sort of tree i am after is one that can contain as many children as necessary, such as the sample I have in my j2sdk directory, j2sdk1.4.2_04\demo\jfc\Sample Tree.

If you do not have this sample available to you i can post the files for you to look at, but the basic jist is more like a directory of sorts.

Mike
 

Posts:6,750
Registered: 1/25/04
Re: tree formed from database  
Aug 2, 2004 10:04 AM (reply 4 of 5)



 
Did you see paulcw's suggestion? Look at the javax.swing.tree package.
 

Posts:13,250
Registered: 24/10/97
Re: tree formed from database  
Aug 2, 2004 11:29 AM (reply 5 of 5)



 
The link you gave pointed to a binary tree, but the
But the principle is the same! Just more than two links. In some ways this is actually easier than a binary tree.

As has been suggested twice before, you can display the tree using a JTree. To do this you just have to create a TreeModel in a similar way to the model produced in the other thread.
 
This topic has 5 replies on 1 page.