开发者

ToolTip on second monitor is displayed at the edge of the monitor

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 tooltip开发者_如何学运维s 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜