Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Folder's First in JTree  RSS feed

 
claude jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am adding folders and leaves to a JTree dynamical. The problem I am having is the placement of the folders when adding them to the tree.
For example, if I had 4 leaves and 4 folders under a rootNode, I would like all folders first and the leaves following.
Good:
RootNode
- Folder 1
- Folder 2
- Folder 3
- Folder 4
- Leaf 1
- Leaf 2
- Leaf 3
- Leaf 4
Bad:
RootNode
- Folder 1
- Leaf 1
- Leaf 2
- Leaf 3
- Folder 2
- Folder 3
- Leaf 4
- Folder 4
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Claude,
I think your app will have to reorder the items because the JTree doesn't see any difference between a folder and a leaf.
Regards,
Manfred.
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "Folder", you mean there are children under the "Folder" treeNode?
If it is, then you can divide all nodes into 2 groups by calling node.isleaf() method, then order it.
Good Luck!
 
claude jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manfred, I was afraid of that.
 
claude jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Renee, that sounds like the solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!