简体   繁体   中英

How to get all childs of root node in jtree?

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".

How to do that? Is there any possibilities?

Please help me, Thanks in advance..

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

tree.getModel().getChild(rootNode, i)

to get the children of the root node.

If your elements implement the TreeNode interface, you can use the available methods:

Otherwise, you can directly query the TreeModel . See the

methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM