Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComponent/7154030/bug7154030.java
38854 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* Portions Copyright (c) 2012 IBM Corporation25*/2627import javax.swing.JButton;28import javax.swing.JDesktopPane;29import javax.swing.JFrame;30import javax.swing.SwingUtilities;3132import java.awt.AWTException;33import java.awt.AlphaComposite;34import java.awt.Color;35import java.awt.Graphics;36import java.awt.Graphics2D;37import java.awt.Rectangle;38import java.awt.Robot;39import java.awt.Toolkit;40import java.awt.image.BufferedImage;4142/* @test 1.1 2012/04/1243* @bug 715403044* @summary Swing components fail to hide after calling hide()45* @author Jonathan Lu46* @library ../../regtesthelpers/47* @library ../../../../lib/testlibrary/48* @build Util49* @build ExtendedRobot50* @run main bug715403051*/5253public class bug7154030 {5455private static JButton button = null;5657public static void main(String[] args) throws Exception {58BufferedImage imageInit = null;5960BufferedImage imageShow = null;6162BufferedImage imageHide = null;6364ExtendedRobot robot = new ExtendedRobot();6566SwingUtilities.invokeAndWait(new Runnable() {6768@Override69public void run() {70JDesktopPane desktop = new JDesktopPane();71button = new JButton("button");72JFrame frame = new JFrame();7374button.setSize(200, 200);75button.setLocation(100, 100);76button.setForeground(Color.RED);77button.setBackground(Color.RED);78button.setOpaque(true);79button.setVisible(false);80desktop.add(button);8182frame.setContentPane(desktop);83frame.setSize(300, 300);84frame.setLocation(0, 0);85frame.setVisible(true);86frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);87}88});8990robot.waitForIdle(500);91imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));9293SwingUtilities.invokeAndWait(new Runnable() {9495@Override96public void run() {97button.show();98}99});100101robot.waitForIdle(500);102imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));103if (Util.compareBufferedImages(imageInit, imageShow)) {104throw new Exception("Failed to show opaque button");105}106107robot.waitForIdle();108109SwingUtilities.invokeAndWait(new Runnable() {110111@Override112public void run() {113button.hide();114}115});116117robot.waitForIdle(500);118imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));119120if (!Util.compareBufferedImages(imageInit, imageHide)) {121throw new Exception("Failed to hide opaque button");122}123124SwingUtilities.invokeAndWait(new Runnable() {125126@Override127public void run() {128button.setOpaque(false);129button.setBackground(new Color(128, 128, 0));130button.setVisible(false);131}132});133134robot.waitForIdle(500);135imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));136137SwingUtilities.invokeAndWait(new Runnable() {138139@Override140public void run() {141button.show();142}143});144145robot.waitForIdle(500);146imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));147148SwingUtilities.invokeAndWait(new Runnable() {149150@Override151public void run() {152button.hide();153}154});155156if (Util.compareBufferedImages(imageInit, imageShow)) {157throw new Exception("Failed to show non-opaque button");158}159160robot.waitForIdle(500);161imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));162163if (!Util.compareBufferedImages(imageInit, imageHide)) {164throw new Exception("Failed to hide non-opaque button");165}166}167}168169170