A tooltip is displayed on the edge of the monitor on the second monitor.

I have a component. The tool ToolTip of the component is installed using the setToolTipText () method. Everything works fine on the first monitor. Now, when I move the frame to the second monitor, tooltips are displayed on the edge of the monitor (to the side of the monitor). This only happens with the tips of this component. The problem also occurs on other machines. However, I only tested it with Vista.

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

The hint text depends on the location of the mouse cursor. Therefore, I can edit the code and override the getToolTipText (MouseEvent e) method. It would be very nice to know what is the cause of this problem before starting to change the code.

Thanks in advance.

+6
java swing tooltip multiple-monitors
source share
1 answer

There are several errors in the Java error database that seem to relate to this, for example.

There is a problem with the prompt when using the configuration with two monitors (with two heads).

JToolTip in JApplet will put a tooltip in the wrong monitor

Problem with button tips with multiple monitor configurations

On is closed as a duplicate of another, it is claimed to be fixed, and the other has a fixed solution.

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 for this is because setLocation() is ultimately Component.reshape() , which in turn calls a method called Component.notifyNewBounds(boolean resized, boolean moved) , which transforms the hierarchy of components by setting the boundaries of each component. From default it is done "lazyily", but they are not installed before the window has moved. The above code causes them to be installed.

That's why the hints start working correctly after dragging a window from one screen to another.

+7
source share

All Articles