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