Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how do I set tooltip text of a treenode?

Posted on 2001-08-02
12
Medium Priority
?
507 Views
Last Modified: 2012-08-14
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
Comment
Question by:TimB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6344040
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
 
LVL 1

Author Comment

by:TimB
ID: 6344121
Bugger!

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

Thanks,


Tim
0
 
LVL 16

Expert Comment

by:Valeri
ID: 6344340
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
Technology Partners: 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!

 
LVL 1

Author Comment

by:TimB
ID: 6344851
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
 
LVL 16

Accepted Solution

by:
Valeri earned 400 total points
ID: 6344928
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
 
LVL 1

Author Comment

by:TimB
ID: 6345082
Fantastic!

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

Thanks for the help!

TimB
0
 
LVL 1

Author Comment

by:TimB
ID: 6345084
Thanks,

TimB
0
 
LVL 92

Expert Comment

by:objects
ID: 6347885
Cool, I've learnt something today :-)

Does that mean that getTreeCellRendererComponent is called every time the mouse moves over the tree cell?
0
 
LVL 16

Expert Comment

by:Valeri
ID: 6348042
Yes, but only if you have registered your JTree in ToolTipManager...

Best Regards,
Valeri
0
 
LVL 92

Expert Comment

by:objects
ID: 6348052
Thanks Valeri :)
0
 
LVL 16

Expert Comment

by:Valeri
ID: 6348075
Hi Objects :-)
I've learned many things reading your answers here...

Thanks !!!
0
 
LVL 92

Expert Comment

by:objects
ID: 6348082
(-:
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question