4

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153

1 Answers1

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.

Scott Wardlaw
  • 652
  • 1
  • 8
  • 13
  • Works perfectly! But I can't use/find the constant WindowState.FULL_SCREEN. Is it just available under Linux? – trinity420 Jul 21 '18 at 20:17