-
Bug
-
Resolution: Fixed
-
P3
-
8u112, 9, 10
-
b31
-
generic
-
os_x
On Mac OS modal dialogs overlapping order is wrong.
Below a test that demonstrates the wrong behavior is provided (a modified test taken from https://stackoverflow.com/questions/46922555/correct-parent-for-modal-dialog-in-swing).
Run the test and create 4 consequently modal dialogs using the button. Their appeared overlapping order is
4 - 1 - 2 - 3
but the expected order is
4 - 3 - 2 - 1
======================
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
MyPanel panel;
private static int shift = 0;
public Main() {
setTitle("This is a frame");
setSize(300, 200);
panel = new MyPanel(this);
add(panel);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
Main frame = new Main();
frame.pack();
frame.setVisible(true);
});
}
private static class MyPanel extends JPanel {
int dialogCounter = 1;
final JFrame theParent;
public MyPanel(JFrame parent) {
super();
theParent = parent;
setPreferredSize(new Dimension(300, 200));
JButton button = new JButton("Press the button");
button.addActionListener(e -> showDialog(theParent));
add(button);
}
private void showDialog(Frame parent) {
JDialog dialog = new JDialog(parent, "This is dialog " + dialogCounter, true);
shift += 40;
dialog.setLocation(parent.getX() + shift, parent.getY() + shift);
setupDialog(dialog);
}
private void setupDialog(JDialog dialog) {
JPanel dialogPanel = new JPanel();
dialogPanel.setPreferredSize(new Dimension(300, 200));
dialogPanel.add(new JLabel("Current dialog count: " + dialogCounter++));
JButton button = new JButton("Open a new modal dialog");
button.addActionListener(e -> showDialog(theParent));
dialogPanel.add(button);
dialog.add(dialogPanel);
dialog.pack();
dialog.setVisible(true);
}
}
}
Below a test that demonstrates the wrong behavior is provided (a modified test taken from https://stackoverflow.com/questions/46922555/correct-parent-for-modal-dialog-in-swing).
Run the test and create 4 consequently modal dialogs using the button. Their appeared overlapping order is
4 - 1 - 2 - 3
but the expected order is
4 - 3 - 2 - 1
======================
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
MyPanel panel;
private static int shift = 0;
public Main() {
setTitle("This is a frame");
setSize(300, 200);
panel = new MyPanel(this);
add(panel);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
Main frame = new Main();
frame.pack();
frame.setVisible(true);
});
}
private static class MyPanel extends JPanel {
int dialogCounter = 1;
final JFrame theParent;
public MyPanel(JFrame parent) {
super();
theParent = parent;
setPreferredSize(new Dimension(300, 200));
JButton button = new JButton("Press the button");
button.addActionListener(e -> showDialog(theParent));
add(button);
}
private void showDialog(Frame parent) {
JDialog dialog = new JDialog(parent, "This is dialog " + dialogCounter, true);
shift += 40;
dialog.setLocation(parent.getX() + shift, parent.getY() + shift);
setupDialog(dialog);
}
private void setupDialog(JDialog dialog) {
JPanel dialogPanel = new JPanel();
dialogPanel.setPreferredSize(new Dimension(300, 200));
dialogPanel.add(new JLabel("Current dialog count: " + dialogCounter++));
JButton button = new JButton("Open a new modal dialog");
button.addActionListener(e -> showDialog(theParent));
dialogPanel.add(button);
dialog.add(dialogPanel);
dialog.pack();
dialog.setVisible(true);
}
}
}
- duplicates
-
JDK-8190522 [macos] Wrong dialog on top with multiple modal dialogs (regression)
-
- Closed
-
- relates to
-
JDK-8169589 [macosx] Activating a JDialog puts to back another dialog
-
- Resolved
-
-
JDK-8182638 [macosx] Active modal dialog is hidden by another non-active one
-
- Resolved
-
-
JDK-8215200 IllegalArgumentException in sun.lwawt.macosx.CPlatformWindow
-
- Resolved
-