编程语言
首页 > 编程语言> > java – 停止全屏窗口以最小化JOptionPane.showMessageDialog?

java – 停止全屏窗口以最小化JOptionPane.showMessageDialog?

作者:互联网

代码

private MainApp() /* Extends JFrame */{
    DisplayMode displayMode = new DisplayMode(800, 600, 16, 75);
    ScreenManager.setFullScreenWindow(displayMode, this);
}

问题

每当我打电话:

JOptionPane.showMessageDialog(MainApp.getInstance(), "Test Message Box");

窗口由于某种原因最小化,然后我必须重新激活它.重新激活窗口后,消息框显示.

问题

有什么方法可以阻止全屏窗口在我调用消息框时最小化吗?

解决方法:

每当显示模式对话框(JOptionPane,JFileChooser等)时,JFrame都会获得一个WINDOW_DEACTIVATED WindowEvent.当您的应用程序显示为全屏时,只需忽略窗口停用:

@Override
protected void processWindowEvent(WindowEvent e)
{
    if (e.getID() == WindowEvent.WINDOW_DEACTIVATED)
    {
        // windowState is set in my set full screen code
        if (windowState == WindowState.FULL_SCREEN)
        {
            return;
        }
    }        

    super.processWindowEvent(e);        
}  

务必正确设置模态对话框的父级:

fileChooser.showOpenDialog(this);

“this”是你最顶级的JPanel,JInternalFrame或JFrame.

标签:java,swing,fullscreen,awt,java-2d
来源: https://codeday.me/bug/20190709/1416608.html