Link to home
Start Free TrialLog in
Avatar of binaryjohn
binaryjohn

asked on

How do I populate a JTree from a database?

Hello experts,

I have a table that consists of employees.

====================================
|  id              |     name                   |      manager      |
====================================
|    1             |   Albert                    |           0             |
|    2             |   Betty                     |           15            |
|    3             |   Charles                  |           12           |
|    4             |   Denise                   |           3             |
|    5             |   Elizabeth                |           8             |
|    6             |   Frank                     |           1             |
|    7             |   George                  |           12            |
|    8             |   Harriet                   |           2             |
|    9             |   Isabelle                 |           11            |
|    10           |   Jerry                     |           3              |
|    11           |   Katie                     |           12            |
|    12           |   Linda                     |           6             |
|    13           |   Mike                      |           11           |
|    14           |   Norman                 |           5             |
|    15           |   Oscar                    |           1             |
|    16           |   Pattrick                  |           3             |
|    17           |   Quincy                   |           11           |
====================================
As you can probably guess the manager column of a record contains a number which is the id of the record of the manager.
I am trying to build a JTree for a swing application. The JTree's structure should be based on the hierarchy of the data.
I have tried pulling all the data into a Person object and populating a Vector with Persons. When I use the Vector to buld DefaultTreeNodes I get a mess.
I would like someone to describe to me in detail a good way to build a TreeModel for my JTree?

Thank you for your help.  
Avatar of valipotor
valipotor

ASKER CERTIFIED SOLUTION
Avatar of dkrukovsky
dkrukovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial