Stop full-screen window from minimizing with JOptionPane.showMessageDialog?

The code

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

Problem

Whenever I call:

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

The window is minimized for some reason, then I need to reactivate it. A message box will appear after reactivating the window.

Question

Is there a way to stop the inclusion of a full-screen window when a message box is called?

+3
source share
1 answer

When a modal dialog is displayed (JOptionPane, JFileChooser, etc.), the JFrame gets a WINDOW_DEACTIVATED WindowEvent. Just ignore window deactivation when your application is displayed in full screen mode:

@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 interface of the modal dialog correctly:

fileChooser.showOpenDialog(this);

"this" - JPanel, JInternalFrame JFrame.

0

All Articles