aspose file tools*
The moose likes Beginning Java and the fly likes JTree data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JTree data from database" Watch "JTree data from database" New topic
Author

JTree data from database

Wynn Teoh
Greenhorn

Joined: Dec 04, 2009
Posts: 10
Hi all,

I'm working on the example at http://java.sun.com/docs/books/tutorial/uiswing/examples/components/GenealogyExampleProject/src/components/GenealogyExample.java

I wanted to customize it in a way the data are pulled from a table instead (folder_id, folder_name, parent_id[foreign key to determine parent] .
Here is my code


If I hardcode it as Person a1 = new Person("Jack (great-granddaddy)"); , it works fine. However, I wanted to put it in a loop, with the variable i :-

How can I make the variable i and the "a" to be combined together? In PHP, we usually combine them with a "." , eg "a".$i;

Thanks Any other example on creating trees from database is greatly appreciated too. Thanks in advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

So you want an array of Person objects? You already used an array in the line just above that, so it looks like you might already have some idea about arrays.
Wynn Teoh
Greenhorn

Joined: Dec 04, 2009
Posts: 10
Hi,

Thanks for your reply. I roughly work on the array from some examples. Don't really know if I'm doing it correctly

Do you mean that the Person objects have to be in array, and not in a loop like what I;m doing now? I want to have the variable "a1","a2","a3"... dynamically. Is it possible?
Thank you!
Wynn Teoh
Greenhorn

Joined: Dec 04, 2009
Posts: 10
Just to add in more info, the example given looks somehting like this :



Then the trees will be in a hierarchy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTree data from database