首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Swing TreeNode转换为Apache多巴哥TreePath?

如何将Swing TreeNode转换为Apache多巴哥TreePath?
EN

Stack Overflow用户
提问于 2017-11-06 11:41:40
回答 1查看 23关注 0票数 0

我有一个Swing TreeNode (DefaultMutableTreeNode),必须为每个Swing TreeNode生成一个Apache多巴哥TreePath:

秋千树:

代码语言:javascript
复制
Root
    Node1
        Child11
        Child12
        Child13
    Node2
        Child21
        Child22
        Child23
    Node3
        Child31
        Child32
        Child33

阿帕奇多巴哥TreePath:

代码语言:javascript
复制
[]
    [0]
        [0,0]
        [0,1]
        [0,2]
    [1]
        [1,0]
        [1,1]
        [1,2]
    [2]
        [2,0]
        [2,1]
        [2,2]

示例:

代码语言:javascript
复制
  Input:  Child11
  Output: [0,1]

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

提前谢谢托马斯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-06 11:59:51

例如,如下所示:

代码语言:javascript
复制
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);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47136192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档