use*_*949 0 java treeview tree data-structures
可能重复:
Java树数据结构?
我想在java中表示层次结构.层次结构可以是表单
Key
|
|-Value1
| |-Value11
| |-Value111
|-Value2
| |-Value22
|-Value3
|-Value4
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我在java中表示这种层次结构的最佳数据结构吗?
基本上你需要的只是一个结构,可以容纳一些孩子,你建模属性.你可以用这样的类结构来表示它:
public class TreeNode {
private Collection<TreeNode> children;
private String caption;
public TreeNode(Collection<TreeNode> children, String caption) {
super();
this.children = children;
this.caption = caption;
}
public Collection<TreeNode> getChildren() {
return children;
}
public void setChildren(Collection<TreeNode> children) {
this.children = children;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
}
Run Code Online (Sandbox Code Playgroud)
你可以看看这里,以便采取一些想法:Java树数据结构?
看到这个答案:
基本上,除了swing包中的JTree之外,标准库中没有提供开箱即用的Tree表示形式的东西。
您可以自己滚动(链接的答案中提供了一些提示),也可以使用实际效果很好的那个提示。
| 归档时间: |
|
| 查看次数: |
47819 次 |
| 最近记录: |