Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
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); } } }
|