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 / November 2005

Tip: Looking for answers? Try searching our database.

how to get renderer component from currently selected node

Thread view: 
William Z. - 28 Nov 2005 22:29 GMT
I have extended a DefaultTreeCellRenderer class so that I can have
JComboBoxes and editable fields in my JTree's nodes. My problem is that
I'd like to dynamically update the tooltips for each tree node to
display different information and I'm not sure how this is done.

Currently I just call setToolTipText() from within my
getTreeCellRendererComponent(...) method.

But I'd really like to make setToolTipText() calls from within the
valueChanged(TreeSelectionEvent tse) of my class which is extended from
TreeSelectionListener(). I think maybe I just don't know how to get the
treecellrenderer component from the currently selected node so that I
can call setToolTipText() on it.

Any ideas, help much appreciated.
NullBock - 28 Nov 2005 23:03 GMT
I think you're making a basic mistake re: rendering components.  In
default JTree implementations, *one* component is used to render the
entire tree.  Moreover, the component isn't actually a child component
of the tree.  Rather, the tree uses the JLabel renderer as a
"rubber-stamp" to draw the tree.

Which means that setting the renderer's tool tip text is going to give
you unpredictable results, at best.  What you need to do, rather, is
update the tool tip text for the *JTree* dynamically via signals from a
mouse-motion listener.  I.e., every time the mouse moves over a new
tree cell, you change the tool tip text for the JTree appropriately.

Walter Gildersleeve
Freiburg, Germany

___________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green
Michael Rauscher - 29 Nov 2005 12:21 GMT
NullBock schrieb:

> Which means that setting the renderer's tool tip text is going to give
> you unpredictable results, at best.  What you need to do, rather, is

Wrong. JTree overrides JComponent#getToolTipText(MouseEvent) in order to
make use of the renderer's tool tip text.

Setting the tool tip of the renderer component gives pretty predictable
results - at least as long as it's done in the
getTreeCellRendererComponent method.

Bye
Michael


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.