Solved

How to hide a node on a JTree

Posted on 1998-07-31
2
1,156 Views
Last Modified: 2008-02-01
How can I hide a node in a JTree?
0
Comment
Question by:srinath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1229648
I'm not sure it's possible at all.  (Assuming, you are talking about the swint JTree component.)  The only node you can hide is the root node.  Use the .setRootVisible(boolean b) method to do so.
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1229649
You can create your own cell renderer by implementing the com.sun.java.swing.tree.TreeCellRenderer interface (or even better, extending the basic cell renderer used by Swing). In getTreeCellRendererComponent() method before returning the component make it invisible (setVisible(false)) if the node (passed there as value parameter) requires that.

Or you can temporarily remove the node from the tree.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question