如何在Java中显示树层次结构? [英] How to display tree hierarchy in Java?

查看:601
本文介绍了如何在Java中显示树层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为Process的数据库中有一个表

I have a table in a database named "Process"

此流程表有3个字段:


  • 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。哪种数据结构更好用于从数据库获取数据并存储在该数据结构中?

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

Q2。如何以图形格式显示该树(进程层次结构)?

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

编辑:

我希望图形格式如下:

推荐答案

Swing有一个内置控件,用于以树格式显示数据,名为 JTree 。它还提供了一个名为 DefaultTreeModel 的数据模型,您可以使用它来存储数据。 此链接给出了一个很好的解释带有数据模型的 JTree

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.

要回答您更新的问题,可以通过 JGraph 这也将提供数据模型,它似乎与树模型swing提供的工作方式类似。

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.

这篇关于如何在Java中显示树层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆