I want to get all child nodes of root node.
我想获取根节点的所有子节点。
ex:
例如:
Root
child1
child1.child1
child2
child2.child1
Now I want to get the two child nodes called "child1" and "child2".
现在我想得到两个名为“child1”和“child2”的子节点。
How to do that? Is there any possibilities?
怎么做?有可能吗?
Please help me, Thanks in advance..
请帮帮我,提前谢谢..
2 个解决方案
#1
15
Get the root of the tree:
获取树的根:
tree.getModel().getRoot();
then get the number of children of this root node:
然后获取此根节点的子节点数:
tree.getModel().getChildCount(rootNode)
then go from 0 to the number of children and call
然后从0到孩子的数量和电话
tree.getModel().getChild(rootNode, i)
to get the children of the root node.
获取根节点的子节点。
#2
4
If your elements implement the TreeNode
interface, you can use the available methods:
如果您的元素实现了TreeNode接口,则可以使用可用的方法:
TreeNode#children
- 树节点#儿童
TreeNode#getChildAt
- 树节点#getChildAt
TreeNode#getChildCount
- 树节点#getChildCount
Otherwise, you can directly query the TreeModel
. See the
否则,您可以直接查询TreeModel。见
TreeModel#getRoot
- TreeModel的#getRoot
TreeModel#getChild
- TreeModel的#getChild
methods
方法
#1
15
Get the root of the tree:
获取树的根:
tree.getModel().getRoot();
then get the number of children of this root node:
然后获取此根节点的子节点数:
tree.getModel().getChildCount(rootNode)
then go from 0 to the number of children and call
然后从0到孩子的数量和电话
tree.getModel().getChild(rootNode, i)
to get the children of the root node.
获取根节点的子节点。
#2
4
If your elements implement the TreeNode
interface, you can use the available methods:
如果您的元素实现了TreeNode接口,则可以使用可用的方法:
TreeNode#children
- 树节点#儿童
TreeNode#getChildAt
- 树节点#getChildAt
TreeNode#getChildCount
- 树节点#getChildCount
Otherwise, you can directly query the TreeModel
. See the
否则,您可以直接查询TreeModel。见
TreeModel#getRoot
- TreeModel的#getRoot
TreeModel#getChild
- TreeModel的#getChild
methods
方法