Stop Fullscreen Window from minimizing when JOptionPane.showMessageDialog?

你。 提交于 2019-12-31 01:14:11

问题


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:


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.



来源:https://stackoverflow.com/questions/9179493/stop-fullscreen-window-from-minimizing-when-joptionpane-showmessagedialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!