The modal dialog gets hidden behind the main frame when clicking somewhere on the frame.
The main frame is blocked (correctly), and the dialog can only be brought back in front by clicking on the main frame title bar.
Tested on a Mac mini (2018, Intel Core i5, macOS Big Sur 11.1)
Tested with AdoptOpenJDK 8 (both HotSpot and OpenJ9), AdoptOpenJDK 11, AdoptOpenJDK 15, Amazon Corretto 15 and Oracle JDK 16.
Can anyone else reproduce this problem?
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
JButton button = new JButton("Open modal dialog");
button.addActionListener(e -> actionOpenDialog(frame));
frame.getContentPane().add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 450);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void actionOpenDialog(JFrame frame) {
JDialog dialog = new JDialog(/* parent */ frame, /* modal */ true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setSize(300, 200);
dialog.setLocationRelativeTo(dialog.getParent());
dialog.setVisible(true);
}
}
Bug report: JDK-8263801.