gpt4 book ai didi

java - 如何将 Swing TreeNode 转换为 Apache Tobago TreePath?

转载 作者:行者123 更新时间:2023-12-02 02:30:49 25 4
gpt4 key购买 nike

我有一个 Swing TreeNode (DefaultMutableTreeNode),并且必须为每个 Swing TreeNode 生成一个 Apache Tobago TreePath:

Swing 树:

Root
Node1
Child11
Child12
Child13
Node2
Child21
Child22
Child23
Node3
Child31
Child32
Child33

Apache 多巴哥树路径:

[]
[0]
[0,0]
[0,1]
[0,2]
[1]
[1,0]
[1,1]
[1,2]
[2]
[2,0]
[2,1]
[2,2]

示例:

  Input:  Child11
Output: [0,1]

如有任何建议,我们将不胜感激。

提前致谢托马斯

最佳答案

例如这样的事情:

public static org.apache.myfaces.tobago.model.TreePath convertPath(TreeNode node) {
List<Integer> list = new ArrayList<>();
TreeNode current = node;
while (current.getParent() != null) {
list.add(0, current.getParent().getIndex(current));
current = current.getParent();
}
return new org.apache.myfaces.tobago.model.TreePath(list);
}

关于java - 如何将 Swing TreeNode 转换为 Apache Tobago TreePath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47136192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com