鼠标运动侦听器事件不会在屏幕的某些区域触发



下面的类演示了我在FSEM中使用MouseMotionListeners时遇到的问题。

public class TestGUI extends JFrame {
Panel panel;
public TestGUI()
{
    panel = new Panel();
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    gd.setFullScreenWindow(this);
    setVisible(false); // use the workaround to the Mac OS X FSEM bug where mouseMotionListeners don't work right away
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(panel);
    setVisible(true);
}
class Panel extends JPanel
{
    public Panel()
    {
        addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e)
            {
                Toolkit.getDefaultToolkit().beep();
            }
        });
        setVisible(true);
    }
}
public static void main(String[] args) {
    new TestGUI();
}
}

问题是这样的:我可以清楚地听到当mouseEvent因为事件处理程序中的Toolkit.getDefaultToolkit().beep();调用而触发时。事件处理程序在大多数屏幕上工作得非常好,除了用于通常有Mac OS X dock的屏幕区域。我通过将底座固定在屏幕的不同侧面来证实这一点,"死区"变成了我固定底座的屏幕一侧。有解决这个问题的方法吗?

我的设置:

Java版本:1.7.0_55。

Mac OS X版本:10.8.5

问题解决。解决方案是在将框架undecorated(true);设置为全屏窗口之前将其设置为正确。

public TestGUI()
{
    panel = new Panel();
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    setUndecorated(true);
    gd.setFullScreenWindow(this);
    setVisible(false); // use the workaround to the Mac OS X FSEM bug where mouseMotionListeners don't work right away
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(panel);
    setVisible(true);
}

也许码头前面有什么看不见的、没有窗户的东西。

最新更新