Search code examples
javaswinglibgdxfullscreenjoptionpane

Java / LibGDX show JOptionPane in front of fullscreen window


I'm making a game in java with libGDX, and I'm currently working on the options menu. I made an ImageButton using Scene2D.ui. When the button is clicked, I want a JOptionPane dialog to appear on screen. This works fine as long as the game is in windowed mode, but if it is in fullscreen mode the JOptionPane dialog appears behind the window. How do I get it to appear on top of all windows, even if one of them is in fullscreen mode?

I've tried using this code, but it doesn't seem to make any difference:

JDialog dialog = new JDialog();
dialog.setAlwaysOnTop(true);

The only solution I can think of would be to create a custom dialog that wouldn't have it's own window, but that would require a lot of work and feels unneccesary.

Thanks!


Solution

  • Use JOptionPane linking it with its parent frame/dialog. It is the first parameter of the static methods, as described in the documentation.

    An example:

    JOptionPane.showInternalMessageDialog(frame, "information", "information", JOptionPane.INFORMATION_MESSAGE);
    

    Where frame is the window JOptionPane should be on top.