• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Folder's First in JTree

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred, I was afraid of that.
 
claude jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Renee, that sounds like the solution.
 
It's a tiny ad only because the water is so cold.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic