?
Solved

how do I set tooltip text of a treenode?

Posted on 2001-08-02
12
Medium Priority
?
505 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

777 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