Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display tree hierarchy in Java?

I have a table in a database named "Process"

This process table has 3 fields:

  • process_id
  • process_name
  • process_parent_id

Now I want to display this parent child hierarchy in Graphical format. So could you please suggest me the following:

Q1. Which data structure would be better to use so as to get data from the database and store in that data structure?

Q2. How to display that tree (process hierarchy) in graphical format?


EDIT:

I want the graphical format something like this:

Tree hierarchy

like image 380
Yatendra Avatar asked Jan 20 '10 13:01

Yatendra


1 Answers

Swing has a built-in control for displaying data in a Tree format called JTree. It also provides a data model called DefaultTreeModel which you can use to store the data. This link gives a pretty good explanation of using a JTree with a data model.

[Edit]:

To answer your updated question, a graph like that could quite well be handled by JGraph which would also provide the data model which seems to work similarly to the Tree model swing provides.

like image 67
Kentaree Avatar answered Sep 30 '22 11:09

Kentaree