Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hiding nodes in a JTree  RSS feed

 
John Danek
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am importing a tree from another program. But in my new program, I don't want to display every node of the tree. I created a class called SimContainerNode that holds the DefaultMutableTreeNodes of the old tree, and adds some fields such as frequency, and isVisible. When I display the JTree, I only want the nods with isVisible = true to show up. How can I acheive this?

I am currently looking into implementing my own Tree Cell Renderer.
 
Paul Clapham
Sheriff
Posts: 22203
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "hiding" mean?

Do you want the tree to appear as if those nodes don't even exist? Or do you want them to take up space, but to just display as blank space?

If it's the former, you'll need a tree model which suppresses the invisible nodes completely. If it's the latter, a tree cell renderer might work.
 
John Danek
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was actually hoping to make it appear they don't even exist, but I have a new idea. The parts I want to show from the old tree are all contained in the same node, so I will simply use this as the node for the new tree. Hopefully I'm able to make changes to the old tree based on selections in the new tree.

Thanks for your help!
 
Paul Clapham
Sheriff
Posts: 22203
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that sounds right. Create a new tree model which delegates all of its actions to the original tree model.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!