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

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

问题描述

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

I have a table in a database named "Process"

这个进程表有3个字段:

This process table has 3 fields:

  • process_id
  • 进程名称
  • 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?

第 2 季度.如何以图形格式显示该树(流程层次结构)?

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

我想要这样的图形格式:

I want the graphical format something like this:

推荐答案

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 提供的 Tree 模型类似.

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天全站免登陆