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 /* 25 @test 26 @bug 8062946 27 @summary Verify Transparency upon iconify/deiconify sequence 28 @run main TransparencyTest 29 */ 30 import java.awt.Color; 31 import java.awt.Point; 32 import java.awt.Robot; 33 import javax.swing.JDialog; 34 import javax.swing.JFrame; 35 import javax.swing.SwingUtilities; 36 37 public class TransparencyTest { 38 39 private static JFrame frame; 40 private static JDialog dialog; 41 private static JDialog backgroundDialog; 42 private static final int WIDTH = 250; 43 private static final int HEIGHT = 250; 44 private static final float OPACITY = 0.60f; 45 private static Point dlgPos; 46 47 public static void createAndShowGUI() { 48 frame = new JFrame("JFrame"); 49 frame.setSize(WIDTH, HEIGHT); 50 frame.setLocation(100, 300); 51 52 dialog = new JDialog(frame, false); 53 dialog.setSize(250, 250); 54 dialog.setUndecorated(true); 55 dialog.setLocation(400, 300); 56 dlgPos = dialog.getLocation(); 57 backgroundDialog = new JDialog(frame, false); 58 backgroundDialog.setSize(250, 250); 59 backgroundDialog.getContentPane().setBackground(Color.red); 60 backgroundDialog.setLocation(dlgPos.x, dlgPos.y); 61 62 frame.setVisible(true); 63 backgroundDialog.setVisible(true); 64 dialog.setVisible(true); 65 } 66 67 public static void main(String[] args) throws Exception { 68 69 Robot robot = new Robot(); 70 // create a GUI 71 SwingUtilities.invokeAndWait(new Runnable() { 72 73 @Override 74 public void run() { 75 createAndShowGUI(); 76 } 77 }); 78 robot.waitForIdle(); 79 Color opaque = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100); 80 81 // set Dialog Opacity 82 SwingUtilities.invokeAndWait(new Runnable() { 83 84 @Override 85 public void run() { 86 dialog.setOpacity(OPACITY); 87 } 88 }); 89 robot.waitForIdle(); 90 91 // iconify frame 92 SwingUtilities.invokeAndWait(new Runnable() { 93 94 @Override 95 public void run() { 96 frame.setExtendedState(JFrame.ICONIFIED); 97 } 98 }); 99 robot.waitForIdle(); 100 101 // deiconify frame 102 SwingUtilities.invokeAndWait(new Runnable() { 103 104 @Override 105 public void run() { 106 frame.setExtendedState(JFrame.NORMAL); 107 } 108 }); 109 robot.waitForIdle(); 110 111 Color transparent = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100); 112 if (transparent.equals(opaque)) { 113 frame.dispose(); 114 throw new RuntimeException("JDialog transparency lost " 115 + "upon iconify/deiconify sequence"); 116 } 117 frame.dispose(); 118 } 119 }