Search code examples
javaswingjframemodal-dialogjoptionpane

Modal dialog not always on top with undecorated frame


I use an undecorated JFrame with a modal dialog. The problem is the modal dialog is always on top when the frame is decorated but nto laways on top when the frame is undecorated. So when I click on my JFrame, the frame is displayed on top and the dialog go underneath.

I use this code.

final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setSize(new Dimension(500, 500));
frame.setUndecorated(true);
frame.setVisible(true);
JOptionPane.showInputDialog("OYE");

Solution

  • JOptionPane.showInputDialog(null, "HelloWorld");
    

    In the above one the parent is null. In your case set parent as your frame.

    Example:

    JOptionPane.showInputDialog(frame, "HelloWorld");
    

    See showInputDialog for more details.