2012-04-26 04:39:11 +00:00
|
|
|
/*
|
2021-01-05 14:46:03 +00:00
|
|
|
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
|
2012-04-26 04:39:11 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Portions Copyright (c) 2012 IBM Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JDesktopPane;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
|
|
|
|
import java.awt.Color;
|
2021-01-05 14:46:03 +00:00
|
|
|
import java.awt.Insets;
|
2012-04-26 04:39:11 +00:00
|
|
|
import java.awt.Rectangle;
|
|
|
|
import java.awt.image.BufferedImage;
|
2020-11-11 08:08:39 +00:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
import java.io.File;
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2016-07-07 14:21:45 +00:00
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @key headful
|
2012-04-26 04:39:11 +00:00
|
|
|
* @bug 7154030
|
|
|
|
* @summary Swing components fail to hide after calling hide()
|
|
|
|
* @author Jonathan Lu
|
|
|
|
* @library ../../regtesthelpers/
|
2018-11-13 15:11:50 +00:00
|
|
|
* @library /lib/client/
|
2012-04-26 04:39:11 +00:00
|
|
|
* @build Util
|
2014-11-21 13:11:03 +00:00
|
|
|
* @build ExtendedRobot
|
2012-04-26 04:39:11 +00:00
|
|
|
* @run main bug7154030
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class bug7154030 {
|
|
|
|
|
|
|
|
private static JButton button = null;
|
2019-12-02 06:28:14 +00:00
|
|
|
private static JFrame frame;
|
2020-11-11 08:08:39 +00:00
|
|
|
private static int locx, locy, frw, frh;
|
2012-04-26 04:39:11 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2019-12-02 06:28:14 +00:00
|
|
|
try {
|
|
|
|
BufferedImage imageInit = null;
|
|
|
|
|
|
|
|
BufferedImage imageShow = null;
|
|
|
|
|
|
|
|
BufferedImage imageHide = null;
|
|
|
|
|
|
|
|
ExtendedRobot robot = new ExtendedRobot();
|
|
|
|
|
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
JDesktopPane desktop = new JDesktopPane();
|
|
|
|
button = new JButton("button");
|
|
|
|
frame = new JFrame();
|
|
|
|
|
|
|
|
button.setSize(200, 200);
|
|
|
|
button.setLocation(100, 100);
|
|
|
|
button.setForeground(Color.RED);
|
|
|
|
button.setBackground(Color.RED);
|
|
|
|
button.setOpaque(true);
|
|
|
|
button.setVisible(false);
|
|
|
|
desktop.add(button);
|
|
|
|
|
|
|
|
frame.setContentPane(desktop);
|
|
|
|
frame.setSize(300, 300);
|
2020-11-11 08:08:39 +00:00
|
|
|
frame.setLocationRelativeTo(null);
|
2019-12-02 06:28:14 +00:00
|
|
|
frame.setVisible(true);
|
|
|
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-18 08:23:55 +00:00
|
|
|
robot.delay(1000);
|
2020-11-11 08:08:39 +00:00
|
|
|
robot.waitForIdle(1000);
|
|
|
|
|
|
|
|
Rectangle bounds = frame.getBounds();
|
2021-01-05 14:46:03 +00:00
|
|
|
Insets insets = frame.getInsets();
|
|
|
|
locx = bounds.x + insets.left;
|
|
|
|
locy = bounds.y + insets.top;
|
|
|
|
frw = bounds.width - insets.left - insets.right;
|
|
|
|
frh = bounds.height - insets.top - insets.bottom;
|
2020-11-11 08:08:39 +00:00
|
|
|
|
|
|
|
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2019-12-02 06:28:14 +00:00
|
|
|
|
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
robot.waitForIdle(500);
|
2020-11-11 08:08:39 +00:00
|
|
|
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2019-12-02 06:28:14 +00:00
|
|
|
if (Util.compareBufferedImages(imageInit, imageShow)) {
|
2020-11-11 08:08:39 +00:00
|
|
|
ImageIO.write(imageInit, "png", new File("imageInit.png"));
|
|
|
|
ImageIO.write(imageShow, "png", new File("imageShow.png"));
|
2019-12-02 06:28:14 +00:00
|
|
|
throw new Exception("Failed to show opaque button");
|
2012-04-26 04:39:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
robot.waitForIdle();
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.hide();
|
|
|
|
}
|
|
|
|
});
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
robot.waitForIdle(500);
|
2020-11-11 08:08:39 +00:00
|
|
|
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
if (!Util.compareBufferedImages(imageInit, imageHide)) {
|
2020-11-11 08:08:39 +00:00
|
|
|
ImageIO.write(imageInit, "png", new File("imageInit.png"));
|
|
|
|
ImageIO.write(imageHide, "png", new File("imageHide.png"));
|
2019-12-02 06:28:14 +00:00
|
|
|
throw new Exception("Failed to hide opaque button");
|
2012-04-26 04:39:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.setOpaque(false);
|
|
|
|
button.setBackground(new Color(128, 128, 0));
|
|
|
|
button.setVisible(false);
|
|
|
|
}
|
|
|
|
});
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
robot.waitForIdle(500);
|
2020-11-11 08:08:39 +00:00
|
|
|
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.show();
|
|
|
|
}
|
|
|
|
});
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
robot.waitForIdle(500);
|
2020-11-11 08:08:39 +00:00
|
|
|
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.hide();
|
|
|
|
}
|
|
|
|
});
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
if (Util.compareBufferedImages(imageInit, imageShow)) {
|
2020-11-11 08:08:39 +00:00
|
|
|
ImageIO.write(imageInit, "png", new File("imageInit.png"));
|
|
|
|
ImageIO.write(imageShow, "png", new File("imageShow.png"));
|
2019-12-02 06:28:14 +00:00
|
|
|
throw new Exception("Failed to show non-opaque button");
|
2012-04-26 04:39:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
robot.waitForIdle(500);
|
2020-11-11 08:08:39 +00:00
|
|
|
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
|
2012-04-26 04:39:11 +00:00
|
|
|
|
2019-12-02 06:28:14 +00:00
|
|
|
if (!Util.compareBufferedImages(imageInit, imageHide)) {
|
2020-11-11 08:08:39 +00:00
|
|
|
ImageIO.write(imageInit, "png", new File("imageInit.png"));
|
|
|
|
ImageIO.write(imageHide, "png", new File("imageHide.png"));
|
2019-12-02 06:28:14 +00:00
|
|
|
throw new Exception("Failed to hide non-opaque button");
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
|
2012-04-26 04:39:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|