1 /* 2 * Copyright (c) 2016, 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 * @key headful 27 * @bug 8157163 8159132 28 * @summary AWT FileDialog does not inherit icon image from parent Frame 29 * @requires os.family=="windows" 30 * @run main FileDialogIconTest 31 */ 32 33 import java.awt.Color; 34 import java.awt.Dialog; 35 import java.awt.FileDialog; 36 import java.awt.Frame; 37 import java.awt.Graphics; 38 import java.awt.Point; 39 import java.awt.Robot; 40 import java.awt.Image; 41 import java.awt.image.BufferedImage; 42 import javax.swing.SwingUtilities; 43 44 public class FileDialogIconTest { 45 private static Frame frame; 46 private static Dialog dialog; 47 48 public static void main(final String[] args) throws Exception { 49 Robot robot; 50 Point p; 51 try { 52 frame = new Frame(); 53 frame.setIconImage(createImage()); 54 frame.setVisible(true); 55 robot = new Robot(); 56 robot.waitForIdle(); 57 robot.delay(200); 58 59 dialog = new FileDialog(frame, "Dialog"); 60 dialog.setModal(false); 61 dialog.setVisible(true); 62 robot.waitForIdle(); 63 robot.delay(1000); 64 65 p = new Point(20, 20); 66 SwingUtilities.convertPointToScreen(p, dialog); 67 Color color = robot.getPixelColor(p.x, p.y); 68 if (!Color.RED.equals(color)) { 69 throw new RuntimeException("Dialog icon was not inherited from " + 70 "owning window. Wrong color: " + color); 71 } 72 } finally { 73 if (dialog != null) { dialog.dispose(); } 74 if (frame != null) { frame.dispose(); } 75 } 76 } 77 78 private static Image createImage() { 79 BufferedImage image = new BufferedImage(64, 64, 80 BufferedImage.TYPE_INT_ARGB); 81 Graphics g = image.getGraphics(); 82 g.setColor(Color.RED); 83 g.fillRect(0, 0, image.getWidth(), image.getHeight()); 84 g.dispose(); 85 return image; 86 } 87 88 }