Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree data from database

 
Wynn Teoh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21317
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add in more info, the example given looks somehting like this :



Then the trees will be in a hierarchy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic