Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ToolTipText's on each node of JTree  RSS feed

 
Ikram Soomro
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How different ToolTipText's can can be applied on each node of JTree.
[ June 22, 2004: Message edited by: Ikram Soomro ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am actually going to answer both your icons and tooltip questions in the one post. Because you will handle all this in a custom leaf renderer.

Here is the code I used to do what you want to do. You will of course need to modify this to suit your needs.

 
Ikram Soomro
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Gregg Bolinger.
 
Ikram Soomro
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Gregg
The code you have posed has a method buildToolTip(value.toString()) is it in DefaultTreeCellRenderer class or it is your own deffined method. actually i have applied diffrent icons on each node and leaf of tree successfully but i am not able to apply diffrent tooltip texts on each node and leaf of tree.

Here is code from getTreeCellRendererComponent method.

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My buildToolTip method was cool, I thought. The value I passed to that method was a ticket number. Then, I would look up the problem for that ticket number and that's what I returned as the tooltip. So the user could hover over the ticket number and see the problem assiated with ticket.

Other than that, it just returned a string which I give to the setToolTipText method of my renderer.

I noticed in your code you have setToolTipText twice. That's fine, except I am not sure about your placement. Your logic is

Set tooltip N for every leaf. Then if leaf is "Administration" set a different tooltip. If not, set a different tooltip. Strange thing is, it's always going to set a tooltip. And it's always the value of the node. So why not just call that method once instead of 2 times.

Also, why are you casting value to a DefaultMutableTreeNode and then calling toString()? You should just be able to do value.toString without the cast.

I'm not sure if any of these are going to fix your problem, but you might try and clean it up a little and see if it makes a difference.
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nowadays, a line like this:

ToolTipManager.sharedInstance().registerComponent(tree);

is needed before the tooltips will display
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!