> I have a model of a tree (represented as a JTree) and I want to display
> only certain nodes of this tree. My problem is that I want to determine
> in the TreeCellRenderer whether this tree node should be displayed.
You can't. You need to provide a TreeModel which provides the different
structure of the data. If you check Sun's GUI tutorial, you will find a
similar example for JTables, where in order to create a sorted table,
the original model is wrapped ("decorated") with a sorted model.
You have the same thing to do. Wrap your complete model in some
filtered model - which you have to implement. That filtered model should
provide the desired version of the tree.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Phil Scholl - 11 Apr 2005 11:28 GMT
> You can't. You need to provide a TreeModel which provides the different
> structure of the data. If you check Sun's GUI tutorial, you will find a
[quoted text clipped - 4 lines]
> model - which you have to implement. That filtered model should provide
> the desired version of the tree.
Thanks!
Looks like I have to do that *sigh*
cheers,
phil
The way to do this is by using a technique called "model filtering".
For a good article on this subject, take a look at:
http://www-106.ibm.com/developerworks/java/library/j-filters/
The article uses ListModel to discuss the subject matter, but the idea
is applicable for all models, including TreeModel.
Regards, Jonck