Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将Swing TreeNode转换为Apache Tobago TreePath?_Java_Apache_Swing_Tree - Fatal编程技术网

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

Java 如何将Swing TreeNode转换为Apache Tobago TreePath?,java,apache,swing,tree,Java,Apache,Swing,Tree,我有一个Swing TreeNode(DefaultMutableTreeNode),并且必须为每个Swing TreeNode生成一个Apache Tobago树路径: 摇摆树: Root Node1 Child11 Child12 Child13 Node2 Child21 Child22 Child23 Node3 Child31 Chil

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

摇摆树:

Root
    Node1
        Child11
        Child12
        Child13
    Node2
        Child21
        Child22
        Child23
    Node3
        Child31
        Child32
        Child33
阿帕奇-多巴哥树路:

[]
    [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);
}
public static org.apache.myfaces.tobago.model.TreePath转换路径(TreeNode节点){
列表=新的ArrayList();
三节点电流=节点;
while(current.getParent()!=null){
添加(0,当前.getParent().getIndex(当前));
current=current.getParent();
}
返回新的org.apache.myfaces.tobago.model.TreePath(列表);
}

例如:

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);
}
public static org.apache.myfaces.tobago.model.TreePath转换路径(TreeNode节点){
列表=新的ArrayList();
三节点电流=节点;
while(current.getParent()!=null){
添加(0,当前.getParent().getIndex(当前));
current=current.getParent();
}
返回新的org.apache.myfaces.tobago.model.TreePath(列表);
}

Hi Sergiy,这是一个非常聪明的解决方案。非常感谢你的帮助。祝您有个美好的一天。ThomasHi Sergiy,这是一个非常聪明的解决方案。非常感谢你的帮助。祝您有个美好的一天。托马斯