views:

218

answers:

1

Hi,

I have got a component. The ToolTip of the component is set by the setToolTipText() method. On the first monitor everything works fine. Now when I move the frame to the second monitor, the tooltips are displayed at the edge of the monitor (on the side to the firt monitor). This happens only with tooltips of this component. The problem appeares on other machines, too. Yet, I've only tested it with Vista.

Why is this? Is this a bug in Swing? How can I fix it?

The tooltip-text depends on the mouse cursor location. Therefore I may edit the code and override the getToolTipText(MouseEvent e) method. It would be realy nice to know, whats the reason for this problem, before starting to change the code.

Thanks in advance.

+4  A: 

There are several bug tickets in the Java bug database which seem to relate to this e.g.

Tooltip issue when using dual monitor (dual head) configuration.

JToolTip in JApplet will place tooltip in wrong monitor

Problem with Action button tooltips with some multiple monitor configurations

On is closed as duplicate of another, one claims to be fixed and another has fix-understood set.

One workaround posted by some user is

frame.pack();
frame.setLocation(location);
frame.setLocation(new Point(0, 0));
frame.setLocation(location);

kieron.wilkinson

The reason this works is that setLocation() eventually calles Component.reshape() which in turn calls a method called Component.notifyNewBounds(boolean resized, boolean moved), which transverses the component hierarchy setting each components bounds. By default this is done "lazyily" but they are not set before the window is moved. The above code forces them to be set.

This is also why the tooltips start working properly after dragging the window from one screen to another.

jitter
Thanks, I think you had some work to research this.I tried to change the code to getToolTipText which works fine after first tests.
Well a couple of google search and reading the three bug reports + postings on them. Then writing the answer. no problem
jitter