I would like to add a tooltip to a JLabel. I read the tooltip tutorial: web page. I wrote the following code and it is just being ignored. No error message or anything.
I would like for it to display the name of the object on that icon in a tooltip when hovering over it.
I would like for it to display the name of the object on that icon in a tooltip when hovering over it.[/QB]
You really dont need to take this approach. The JComponent has a getToolTipText() method which returns a String which is displayed as the tooltip. This method is called internally whenever the tooltip is to be displayed. All JComponents are registered with the ToolTipManager by default.
So, what you need to do is make your IconLabel extend the JLabel or some other JComponent. In the constructor, you can accept the object which is to be represented by this IconLabel. Then you just override the getToolTipText() which will return the appropriate String based on the Object.
My IconLabel is already an instance of JLabel. Do I have to add something in the MouseListener in order to display the tooltip when the mouse is moved over the icon?
astThread = new Thread(this); astThread.start(); }
Marc Beck
Ranch Hand
Joined: Sep 09, 2006
Posts: 36
posted
0
Thanks for trying to help. I have been very busy with other things and just got back to this problem. I am using the setTooltipText() method, but it is being completely ignored. Am I missing something? Where do I need to put the getToolTipText?
Originally posted by Marc Beck: I am using the setTooltipText() method, but it is being completely ignored. Am I missing something? Where do I need to put the getToolTipText?
Usually its something like label.setToolTipText("This is a tool tip"); Why dont you post your code where you are setting the tool tip so we can figure out whats missing?
Marc Beck
Ranch Hand
Joined: Sep 09, 2006
Posts: 36
posted
0
The code is part of a game that is about 4000 lines and I've been working on it for over a year.
The picture of the planet is displayed fine. I would like for the tooltip to show the name of the planet when the player moves the cursor over the picture, so I can get rid of the NameLabel.
Marc Beck
Ranch Hand
Joined: Sep 09, 2006
Posts: 36
posted
0
Nevermind, I figured it out on my own when I looked on the code again shortly after my last post. But thanks for trying.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.