I have a JTree with multiple "roots" (Of course, I actually have an invisible real root with multiple children).
The nodes expand and collapse on double click, but there's no visual indication that you can do this as there is no expander icon.
This is made worse by the fact that the tree is collapsed by default, but expanding the "roots" doesn't really help, as each has many children and it would look cluttered.
Is there a way to display the expander icons without making the real (and utterly valueless) root visible?
Any other suggestions to make the display clearer welcome.
A hidden node is one which is under a collapsed ancestor.
JTree class is a powerful Swing component for displaying tree-structured data. Like all Swing components, JTree relies on a separate model object to hold and represent the data that it displays. Most Swing components create this model object automatically, and you never need to work with it explicitly.
Would tree.setShowsRootHandles(true)
be a good way to display those "expander icons" ?
A tree typically also performs some look-and-feel-specific painting to indicate relationships between nodes. You can customize this painting in a limited way.
- First, you can use
tree.setRootVisible(true)
to show the root node or tree.setRootVisible(false) to hide it.- Second, you can use
tree.setShowsRootHandles(true)
to request that a tree's top-level nodes — the root node (if it is visible) or its children (if not) — have handles that let them be expanded or collapsed.
Check also your look and feel to be sure what the renderer does with your tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With