How to display tree hierarchy in Java?

巧了我就是萌 提交于 2019-11-30 19:21:32
Kentaree

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.

As others have suggested, using JTree is one possible solution. However, if you wish to have more control over the appearance of your tree I suggest checking out the JUNG graphing library. This can potentially give you great results but will require more work.

For the hierarchy in graphical format, what about a JTree ? http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Re Q1: You could find on internet resources several Java implementations of Tree structure, for example this generic tree.

Re Q2: One alternative is using JTree. Check the Java Tutorial trail on How to use Trees

JGraphT could be a good starting point to build something like your example. Check the demo at http://jgrapht.sourceforge.net/visualizations.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!