Tooltip in JTable Issue

I have a JTable that is returning tooltips for each cell in the table. The tooltips are dynamic based on the data contained in the cell. I only want this data to be shown if the user purosely hovers their mouse over a cell.

The tooltip works correctly for the first cell they mouse over due to the ToolTipManager.sharedInstance().setInitialDelay( XXXXX ) method.

The problem is that once it is up, it stays up as they move through the table. I believe the reason that setReshowDelay isn't working is due to the fact that at no point (until it leaves the table) is it over an area that doesn't have a valid tooltip.

When I leave the table with the mouse and return, the initial delay is again in effect. I want that to happen every time the user moves to a new cell.

Any ideas?

[809 byte] By [cochranjda] at [2007-11-26 15:38:56]
# 1

> I believe the reason that setReshowDelay isn't working

Its working. Move you mouse over a cell and let it sit there. The tooltip will show and then hide. Now move your mouse a fex pixels in the same cell. The tooltip will reappear. MouseEvents are generated every time you move the mouse a pixel which affects the way the tooltip is displayed.

> I want that to happen every time the user moves to a new cell.

Well then you will need to track the current cell and then every time you leave the cell you will need to hide the tooltip.

So you would need to add a MouseListener to the table and handle the mouseMoved() event. Use the MouseEvent to calculate the cell you are currently in. When the cell changes you need to hide the tooltip manually. The following code should work:

Action toolTipAction = component.getActionMap().get("hideTip");

if (toolTipAction != null)

{

ActionEvent hideTip = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, "");

toolTipAction.actionPerformed( hideTip );

}

camickra at 2007-7-8 21:57:14 > top of Java-index,Desktop,Core GUI APIs...
# 2

To get my tooltip, I over rode JTable's getToolTipText( MouseEvent e_ ) method.

How do I get ahold of the component that the tool tip belongs to? I've tried pulling it out of the mouse event, but that doesn't seem to accomplish what I'm attempting to do.

I definitely appreciate the help.

cochranjda at 2007-7-8 21:57:14 > top of Java-index,Desktop,Core GUI APIs...
# 3

> To get my tooltip, I over rode JTable's getToolTipText( MouseEvent e_ ) method.

That has nothing to do with what I suggested so I'm not sure what you are trying to do.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-8 21:57:14 > top of Java-index,Desktop,Core GUI APIs...
# 4

Yeah, I guess that was unneccessary.

The thing I was confused over is where I get the component that I need. I've tried getting the renderer component from the cell, the editor component from the cell, as well as the table itself and none of them seem to have an effect (they all return null for toolTipAction.

I think I may just be thinking about this wrong, and my previous post was just a bad way of saying I didn't initially have the component in hand and asking where I am supposed to pull it from.

cochranjda at 2007-7-8 21:57:14 > top of Java-index,Desktop,Core GUI APIs...
# 5
You add a MouseListener to the table. The MouseEvent contains the source of the event (ie. the table).
camickra at 2007-7-8 21:57:14 > top of Java-index,Desktop,Core GUI APIs...