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 /* @test 25 * @bug 8190230 26 * @summary [macosx] Order of overlapping of modal dialogs is wrong 27 * @run main SiblingChildOrderTest 28 */ 29 30 import javax.swing.*; 31 import java.awt.*; 32 33 public class SiblingChildOrderTest 34 35 { 36 static Color[] colors = new Color[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW}; 37 static int[] x = new int[]{200, 150, 100, 50}; 38 static int[] y = new int[]{200, 150, 100, 50}; 39 static JDialog[] dlgs = new JDialog[4]; 40 private static JFrame frame; 41 42 public static void main(String args[]) throws Exception { 43 SwingUtilities.invokeAndWait(() -> { 44 frame = new JFrame("FRAME"); 45 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 46 frame.setBounds(50, 50, 400, 400); 47 frame.setVisible(true); 48 }); 49 50 for (int i = 0; i < colors.length; i++) { 51 int finalI = i; 52 SwingUtilities.invokeLater(() -> { 53 dlgs[finalI] = new JDialog(frame, "DLG " + finalI, true); 54 dlgs[finalI].getContentPane().setBackground(colors[finalI]); 55 dlgs[finalI].setBounds(x[finalI], y[finalI], 200, 200); 56 dlgs[finalI].setVisible(true); 57 58 }); 59 } 60 61 Robot robot = new Robot(); 62 robot.waitForIdle(); 63 robot.delay(200); 64 65 for (int i = 0; i < colors.length; i++) { 66 Color c = robot.getPixelColor(x[i] + 190, y[i] + 190); 67 if (!c.equals(colors[i])) { 68 throw new RuntimeException("Expected " + colors[i] + " got " + c); 69 } 70 } 71 72 for (int i = 0; i < colors.length; i++) { 73 SwingUtilities.invokeLater(dlgs[i]::dispose); 74 } 75 76 SwingUtilities.invokeLater(frame::dispose); 77 78 } 79 }