1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8190230 27 * @summary [macosx] Order of overlapping of modal dialogs is wrong 28 * @key headful 29 * @run main SiblingChildOrderTest 30 */ 31 32 import javax.swing.*; 33 import java.awt.*; 34 35 public class SiblingChildOrderTest 36 37 { 38 static Color[] colors = new Color[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW}; 39 static int[] x = new int[]{200, 150, 100, 50}; 40 static int[] y = new int[]{200, 150, 100, 50}; 41 static JDialog[] dlgs = new JDialog[4]; 42 private static JFrame frame; 43 44 public static void main(String args[]) throws Exception { 45 SwingUtilities.invokeAndWait(() -> { 46 frame = new JFrame("FRAME"); 47 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 48 frame.setBounds(50, 50, 400, 400); 49 frame.setVisible(true); 50 }); 51 52 for (int i = 0; i < colors.length; i++) { 53 int finalI = i; 54 SwingUtilities.invokeLater(() -> { 55 dlgs[finalI] = new JDialog(frame, "DLG " + finalI, true); 56 dlgs[finalI].getContentPane().setBackground(colors[finalI]); 57 dlgs[finalI].setBounds(x[finalI], y[finalI], 200, 200); 58 dlgs[finalI].setVisible(true); 59 60 }); 61 } 62 63 Robot robot = new Robot(); 64 robot.waitForIdle(); 65 robot.delay(200); 66 67 for (int i = 0; i < colors.length; i++) { 68 Color c = robot.getPixelColor(x[i] + 190, y[i] + 190); 69 if (!c.equals(colors[i])) { 70 throw new RuntimeException("Expected " + colors[i] + " got " + c); 71 } 72 } 73 74 for (int i = 0; i < colors.length; i++) { 75 SwingUtilities.invokeLater(dlgs[i]::dispose); 76 } 77 78 SwingUtilities.invokeLater(frame::dispose); 79 80 } 81 }