Stop Fullscreen Window from minimizing when JOptio

2019-02-24 13:19发布

The Code

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

The Problem

Whenever I call:

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

The Window minimizes for some reason, then I have to re-activate it. The Message Box shows after I re-activate the Window.

The Question

Is there any way to stop the Fullscreen Window from minimizing when I call the Message Box?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-24 13:47

Whenever a modal dialog is displayed (JOptionPane, JFileChooser, etc.), the JFrame gets a WINDOW_DEACTIVATED WindowEvent. Simply ignore the window deactivation when your app is displayed as fullscreen:

@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);        
}  

Be sure to set the parent of modal dialog correctly:

fileChooser.showOpenDialog(this);

Where "this" is your top most JPanel, JInternalFrame, or JFrame.

查看更多
登录 后发表回答