We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
查看 DefaultMutableTreeNode。它不通用,但在其他方面似乎符合要求。尽管它位于 javax.swing 包中,但它不依赖于任何 AWT 或 Swing 类。事实上,源代码实际上有注释
// ISSUE: this class dependents Nothing in AWT -- move to java.util?
Check out DefaultMutableTreeNode. It's not generic, but otherwise seems to fit the bill. Even though it's in the javax.swing package, it doesn't depend on any AWT or Swing classes. In fact, the source code actually has the comment
// ISSUE: this class depends on nothing in AWT -- move to java.util?
使用泛型实现树非常简单,为什么不自己尝试一下呢?如果您对泛型不满意,可以尝试声明一个包含实现接口的元素的树,然后让所有不同的区域元素实现该接口。
Implementing a tree using generics is pretty simple, why not give it a try yourself? If you're not comfortable with generics, you can try declaring a tree that contains elements that implement an interface, then just have all your various region elements implement that interface.
您是指树形小部件还是树状数据结构?如果您谈论的是 Tree 小部件,那么 Swing 有一个实现。
JTree
Do you mean a Tree Widget or a tree like data structure? If you are talking about a Tree widget, then Swing has an implementation.
JTree
您所描述的更像是文档对象模型(DOM)。通常,当人们提到“树”数据结构时,他们谈论的是平衡二叉树(如红黑树,它确实存在于 Java 集合库中)。但这些类型的树仅用于快速有序插入和查找。
不管怎样,大多数时候,当人们使用 DOM 时,他们是在读取或写入 XML,但是您没有理由不能将 DOM 用于您自己的任意分层数据。即使您从未将其持久化为 XML。
What you're describing is much more like a Document Object Model (DOM). Usually when people refer to a "Tree" data structure, they're talking about a balanced binary tree (like a red-black tree, which certainly does exist in the Java collections library). But those kinds of trees are just for fast in-order insertions and lookups.
Anyhow, most of the time, when people use a DOM, they're reading or writing XML, but there's no reason you couldn't use a DOM for your own arbitrary hierarchical data. Even if you never persist it to XML.
像这样的http://www.java-tips.org/java-se-tips/java.lang/red-black-tree-implementation-in-java.html 工作吗?
另外,从 OpenJDK 的 java.util.TreeMap 源开始怎么样? http://download.java.net/openjdk/jdk7/
Would something like this http://www.java-tips.org/java-se-tips/java.lang/red-black-tree-implementation-in-java.html work?
Also, how about starting with the java.util.TreeMap source from the OpenJDK? http://download.java.net/openjdk/jdk7/