Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hiding the root node on a custom JTree?

843805May 10 2006
I am working on a project and for it I needed a JTree that has checkboxes in it. I found the code online (http://www.crionics.com/products/opensource/faq/swing_ex/JTreeExamples2.html) and it works just fine. The tree draws, it looks nice, I can get it to do everything that I want it to except one thing.

I can't hide the root node.

When I call the JTree's setRootVisible it hides the root, and everything else. With the root hidden the rest of the tree (the root's children, and their children) don't draw. At all.

I've been trying for a while now and this is driving me nuts. I'm rather new to GUI programming so I'm having to fight my way along during all this. I've put in debugging code and with the root node the custom tree renderer that I'm using to draw the tree's nodes gets called tons of times (as you would expect). When I turn setRootVisible off, it doesn't get called AT ALL.

How can I make my tree display the children, but not the root? I'm using the same kind of object for everything in the tree, the checkbox node. If I used a default mutable tree node for the root would that help? The problem with that is that I tried to implement that and then my custom cell renderer gets mad because the object is not a checkbox node so I'd have to put in code to check each node as rendering is called to see if it is a checkbox node and if not it would have to call the default tree cell renderer which is rather complex if it can be avoided (since I don't even know if that would work).

Can anyone give me some advice on this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2006
Added on May 10 2006
0 comments
421 views