Heavy Tooltip Displaying Repeatedly when using Custom TooltipLocation
Check this one out:
If you display a tooltip so that it is both heavy weight and it is directly under the cursor location the tooltip will display over and over. It will display initially and then hide after a delay, then will display again after a delay. It will do this over and over unendingly.
import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.*;
publicclass HeavyWeightToolTipBugextends JPanel
{
public Point getToolTipLocation(MouseEvent event)
{
Point p = event.getPoint();
p.translate(-5, -5);
return p;
}
publicstaticvoid main(String[] args)
{
HeavyWeightToolTipBug panel =new HeavyWeightToolTipBug();
panel.setToolTipText("A really really long string so that a medium weight popup window will be used for the tooltip instead of a light weight popup window");
JFrame frame =new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel);
frame.setSize(400, 300);
frame.setVisible(true);
}
}
[1847 byte] By [
philpa] at [2007-10-3 4:23:52]

Oops, hit post instead of preview...
I believe this is because the heavy weight popup tooltip steals the focus from the tooltip component owner. Once the heavy weight tooltip goes away a mouseEntered event gets generated again for the tooltip component owner causing the tooltip to display again.
Any idea for a work around?
philpa at 2007-7-14 22:26:16 >

> I believe this is because the heavy weight popup tooltip steals the focus from the tooltip component owner.
Same problem occurs with a short tool tip message.
The problem is related to your translate. I changed the value to (20, 20) and it works fine for long and short tool tips. So I think the problem might be related to the tooltip displaying the the area of the icon.
The whole point of my translate was to put the heavyweight tooltip directly under my cursor. My real world example is that I have a table and I would like a tooltip to display the cell value text if the user mouses over it. But instead of displaying the tooltip below the curser (x axis) I'd like the tooltip to display right over the top of the cell: which is directly under my curser (z-axis)
This seems to work fine for me provided the ToolTipManager uses a lightweight tooltip window. It's only a problem is if my cell value is so long that the ToolTipManager is forced to use a heavyweight component.
I'm using jdk1.5 and if I set the tooltip to:
panel.setToolTipText("A Short Tooltip");
my example works correctly because the ToolTipManager uses a lightweight component. The ToolTipManager can use a lightweight tooltip window because the entire tooltip window can be displayed within the bounds of the JFrame.
So, one might ask, "why is your cell value so dang large". Well, my UI is ultimately displaying values from a database that I have no control over and in this case the field I'm displaying is a CLOB that has a very long peice of text in it.
philpa at 2007-7-14 22:26:16 >

> I'm using jdk1.5 and if I set the tooltip to:
I'm using, JDK1.4.2 and the problem appears to be related to the tool tip location relative to the mouse.
I just changed the example to use use a translate of (-20, -20) and it works fine.
When I use a translate of +/- 20 the the tooltip is not displayed in the bounds of the mouse icon (it appears anyway) and I don't have a problem.
When I use -5, the mouse icon is over the tool tip and I have the problem.
So my suggestion is to try playing with you translate values.
> So, one might ask, "why is your cell value so dang large".
You could also use HTML to display the tooltip. Wrap your text in some HTML tag that is limited to a certain width, then it will wrap automatically.
Sorry, I guess I'm not explaining it very well. In my real world example the cursor will alway be right over the tooltip (z-axis). With how I want it to work there is just no work around for that fact.
The example code where I use translate(-5, -5) is just to illustrate the problem. For now I do exactly as you suggest and take the default location of the tooltip which is below the cursor (x-axis) and not under it (z-axis).
I can't think of a workaround for this. Hoping some discussion will bring one to light...
philpa at 2007-7-14 22:26:16 >
