2017-11-06 1 views
0

내가 스윙의 TreeNode (DefaultMutableTreeNode의)가 각각의 스윙 TreeNode를위한 아파치 토바고의 TreePath를 생성 할 수 있습니다Swing TreeNode를 Apache Tobago TreePath로 변환하는 방법?

스윙 트리 :

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

아파치 토바고의 TreePath :

[] 
    [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] 

이온은 많이 감사 할 것입니다. 이 같은 예를 들어 뭔가를 미리 토마스

답변

2

에서

감사 :

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); 
} 
+0

안녕 세르지, 이 아주 똑똑한 솔루션입니다. 많은 도움에 감사드립니다. 좋은 하루 되세요. 토마스 – ThomasMuller

관련 문제