1 /* 2 * Copyright (c) 2012, 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 * Portions Copyright (c) 2012 IBM Corporation 26 */ 27 28 import javax.swing.JButton; 29 import javax.swing.JDesktopPane; 30 import javax.swing.JFrame; 31 import javax.swing.SwingUtilities; 32 33 import java.awt.AWTException; 34 import java.awt.AlphaComposite; 35 import java.awt.Color; 36 import java.awt.Graphics; 37 import java.awt.Graphics2D; 38 import java.awt.Rectangle; 39 import java.awt.Robot; 40 import java.awt.Toolkit; 41 import java.awt.image.BufferedImage; 42 43 /* 44 * @test 45 * @key headful 46 * @bug 7154030 47 * @summary Swing components fail to hide after calling hide() 48 * @author Jonathan Lu 49 * @library ../../regtesthelpers/ 50 * @library ../../../../lib/testlibrary/ 51 * @build Util 52 * @build ExtendedRobot 53 * @run main bug7154030 54 */ 55 56 public class bug7154030 { 57 58 private static JButton button = null; 59 60 public static void main(String[] args) throws Exception { 61 BufferedImage imageInit = null; 62 63 BufferedImage imageShow = null; 64 65 BufferedImage imageHide = null; 66 67 ExtendedRobot robot = new ExtendedRobot(); 68 69 SwingUtilities.invokeAndWait(new Runnable() { 70 71 @Override 72 public void run() { 73 JDesktopPane desktop = new JDesktopPane(); 74 button = new JButton("button"); 75 JFrame frame = new JFrame(); 76 77 button.setSize(200, 200); 78 button.setLocation(100, 100); 79 button.setForeground(Color.RED); 80 button.setBackground(Color.RED); 81 button.setOpaque(true); 82 button.setVisible(false); 83 desktop.add(button); 84 85 frame.setContentPane(desktop); 86 frame.setSize(300, 300); 87 frame.setLocation(0, 0); 88 frame.setVisible(true); 89 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 90 } 91 }); 92 93 robot.waitForIdle(500); 94 imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 95 96 SwingUtilities.invokeAndWait(new Runnable() { 97 98 @Override 99 public void run() { 100 button.show(); 101 } 102 }); 103 104 robot.waitForIdle(500); 105 imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 106 if (Util.compareBufferedImages(imageInit, imageShow)) { 107 throw new Exception("Failed to show opaque button"); 108 } 109 110 robot.waitForIdle(); 111 112 SwingUtilities.invokeAndWait(new Runnable() { 113 114 @Override 115 public void run() { 116 button.hide(); 117 } 118 }); 119 120 robot.waitForIdle(500); 121 imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 122 123 if (!Util.compareBufferedImages(imageInit, imageHide)) { 124 throw new Exception("Failed to hide opaque button"); 125 } 126 127 SwingUtilities.invokeAndWait(new Runnable() { 128 129 @Override 130 public void run() { 131 button.setOpaque(false); 132 button.setBackground(new Color(128, 128, 0)); 133 button.setVisible(false); 134 } 135 }); 136 137 robot.waitForIdle(500); 138 imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 139 140 SwingUtilities.invokeAndWait(new Runnable() { 141 142 @Override 143 public void run() { 144 button.show(); 145 } 146 }); 147 148 robot.waitForIdle(500); 149 imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 150 151 SwingUtilities.invokeAndWait(new Runnable() { 152 153 @Override 154 public void run() { 155 button.hide(); 156 } 157 }); 158 159 if (Util.compareBufferedImages(imageInit, imageShow)) { 160 throw new Exception("Failed to show non-opaque button"); 161 } 162 163 robot.waitForIdle(500); 164 imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); 165 166 if (!Util.compareBufferedImages(imageInit, imageHide)) { 167 throw new Exception("Failed to hide non-opaque button"); 168 } 169 } 170 }