我有一个Swing TreeNode (DefaultMutableTreeNode),必须为每个Swing TreeNode生成一个Apache多巴哥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]如有任何建议,将不胜感激。
提前谢谢托马斯
发布于 2017-11-06 11:59:51
例如,如下所示:
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);
}https://stackoverflow.com/questions/47136192
复制相似问题