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 / General / January 2006

Tip: Looking for answers? Try searching our database.

Hiding some nodes in jtree

Thread view: 
Srikanth - 19 Jan 2006 09:32 GMT
How can i  hide and show some nodes in the tree based on some criteria?
Right now i done it this way(given below). But its not working...

1) I have extended the DefaultMutableTreeNode into CustomTreeNode which
contains a variable called visible and contains methods setVisible()
and isVisible()
2) I have overridden the DefaultTreeModel.
    a) getChildCount() gives the count of the visible node
    b) getChildIndex() gives the index of the nodes among the visible
nodes
    c) getChild() gives that node.
hiwa - 19 Jan 2006 09:41 GMT
That should be a cell renderer issue ...
Srikanth - 19 Jan 2006 09:48 GMT
No that node shouldn't be rendered at all..
Thomas Weidenfeller - 19 Jan 2006 11:01 GMT
> How can i  hide and show some nodes in the tree based on some criteria?
> Right now i done it this way(given below). But its not working...
[quoted text clipped - 7 lines]
> nodes
>      c) getChild() gives that node.

That's going in the right direction. What one typically does is to
implement a wrapper model. It wraps the original model, provides the
same API (TreeModel), but does some filtering on the original model data
before passing it through.

In your case such a wrapper model would take your isVisible() flag in
the tree nodes into account when responding to getChild...() method
invocations. Very similar to what you did in your subclassed model
implementation.

There is some example for a JList or JTable in Sun's GUI tutorial to
sort list data before it is displayed. The structure is the same for a
Tree Model.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



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



©2009 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.