Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

Implementing a view via a TreeCellRenderer in a JTree

Thread view: 
Phil Scholl - 11 Apr 2005 10:47 GMT
Hi!

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.

If I return a null reference in getTreeCellRendererComponent(...) a
NullPointerException is thrown. If I call in the TreeCellRenderer
setVisible(false) on the returned Component, it is displayed nevertheless.

Does anybody know how to accomplish this?

Thanks!
Phil
Thomas Weidenfeller - 11 Apr 2005 11:08 GMT
> 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
jonck@vanderkogel.net - 11 Apr 2005 12:17 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.