• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

how do I set tooltip text of a treenode?

Hello,

Does anyone know how to set the tooltip text on the node of a JTree? Initially I'd like the node's tooltip text to display "Hello" when I hover the mouse over that node.



I have this code (but it's not working :(

public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
     System.out.println("inside tree cell renderer");
     javax.swing.JComponent c = (javax.swing.JComponent)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
     
      c.setToolTipText("hhhhhh");
     return c;
}
0
TimB
Asked:
TimB
  • 4
  • 4
  • 4
1 Solution
 
objectsCommented:
I don't think tool tips are supported for tree cells.
The renderer is only used to 'rubberstamp' the cells so it won't work.
0
 
TimBAuthor Commented:
Bugger!

I'll leave the question open for a bit though - just in case someone can come up with something.

Thanks,


Tim
0
 
ValeriCommented:
Try it :

public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean
selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        javax.swing.JLabel c = (javax.swing.JLabel)super.getTreeCellRendererComponent(tree, value,
selected, expanded, leaf, row, hasFocus);
   
    c.setToolTipText("hhhhhh");
    return c;
}


You must add this line as well :

ToolTipManager.sharedInstance().registerComponent(yourJTree);

Best Regards,
Valeri
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TimBAuthor Commented:
Hi Valeri,

That didn't seem to work either.  I've tried sticking some system.out's in the code so I can see when the rellrenderer get's called.  I'm not missing something silly like a mouse listener for when I hover over ther treenode am I?

Thanks for the reply anyhow,

TimB
0
 
ValeriCommented:
The proposed code works !!! I'm sure, because I have JTree with ToolTips in my project. There is something wrong in your code, check it again...

Do you have it :
yourJTree.setCellRenderer(new YourRenderer());

Best Regards,
Valeri
0
 
TimBAuthor Commented:
Fantastic!

It works! I'd missed out the - ToolTipManager.sharedInstance().registerComponent(yourJTree); - part that you suggested.

Thanks for the help!

TimB
0
 
TimBAuthor Commented:
Thanks,

TimB
0
 
objectsCommented:
Cool, I've learnt something today :-)

Does that mean that getTreeCellRendererComponent is called every time the mouse moves over the tree cell?
0
 
ValeriCommented:
Yes, but only if you have registered your JTree in ToolTipManager...

Best Regards,
Valeri
0
 
objectsCommented:
Thanks Valeri :)
0
 
ValeriCommented:
Hi Objects :-)
I've learned many things reading your answers here...

Thanks !!!
0
 
objectsCommented:
(-:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now