Java中现有的树库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23012529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exisiting Tree Library in Java?
提问by user3398326
I am trying to create a Tree like structure were i have a root node and then i can add childrens to the root node and continue the process. I am not really interested in sorting. All i want is a tree like structure since i am creating an Org Chart.
如果我有一个根节点,我正在尝试创建一个类似树的结构,然后我可以将子节点添加到根节点并继续该过程。我对排序并不感兴趣。我想要的只是一个树状结构,因为我正在创建一个组织结构图。
Is there an exisitng java library that will let me add root node, child node or for example get a child node from a tree and then add child to those nodes as well. Or maybe get all the leaf node from a tree.
是否有一个现有的 java 库可以让我添加根节点、子节点或例如从树中获取子节点,然后将子节点添加到这些节点。或者也许从树中获取所有叶节点。
I am trying to avoid creating one on my own just to save time ? Any libraries you can suggest will be of great help .
我试图避免自己创建一个只是为了节省时间?您可以建议的任何库都会有很大帮助。
Note: I am not using Swing or AWT components.
注意:我没有使用 Swing 或 AWT 组件。
回答by Russell Zahniser
The TreeModel
interface in Java is designed for this. DefaultTreeModel
supports adding any number of children to a node, listening on a node, and looking up nodes by path.
TreeModel
Java 中的接口就是为此而设计的。DefaultTreeModel
支持向节点添加任意数量的子节点、监听节点以及按路径查找节点。