Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComponent/7154030/bug7154030.java
38854 views
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
/* @test 1.1 2012/04/12
44
* @bug 7154030
45
* @summary Swing components fail to hide after calling hide()
46
* @author Jonathan Lu
47
* @library ../../regtesthelpers/
48
* @library ../../../../lib/testlibrary/
49
* @build Util
50
* @build ExtendedRobot
51
* @run main bug7154030
52
*/
53
54
public class bug7154030 {
55
56
private static JButton button = null;
57
58
public static void main(String[] args) throws Exception {
59
BufferedImage imageInit = null;
60
61
BufferedImage imageShow = null;
62
63
BufferedImage imageHide = null;
64
65
ExtendedRobot robot = new ExtendedRobot();
66
67
SwingUtilities.invokeAndWait(new Runnable() {
68
69
@Override
70
public void run() {
71
JDesktopPane desktop = new JDesktopPane();
72
button = new JButton("button");
73
JFrame frame = new JFrame();
74
75
button.setSize(200, 200);
76
button.setLocation(100, 100);
77
button.setForeground(Color.RED);
78
button.setBackground(Color.RED);
79
button.setOpaque(true);
80
button.setVisible(false);
81
desktop.add(button);
82
83
frame.setContentPane(desktop);
84
frame.setSize(300, 300);
85
frame.setLocation(0, 0);
86
frame.setVisible(true);
87
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
88
}
89
});
90
91
robot.waitForIdle(500);
92
imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
93
94
SwingUtilities.invokeAndWait(new Runnable() {
95
96
@Override
97
public void run() {
98
button.show();
99
}
100
});
101
102
robot.waitForIdle(500);
103
imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
104
if (Util.compareBufferedImages(imageInit, imageShow)) {
105
throw new Exception("Failed to show opaque button");
106
}
107
108
robot.waitForIdle();
109
110
SwingUtilities.invokeAndWait(new Runnable() {
111
112
@Override
113
public void run() {
114
button.hide();
115
}
116
});
117
118
robot.waitForIdle(500);
119
imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
120
121
if (!Util.compareBufferedImages(imageInit, imageHide)) {
122
throw new Exception("Failed to hide opaque button");
123
}
124
125
SwingUtilities.invokeAndWait(new Runnable() {
126
127
@Override
128
public void run() {
129
button.setOpaque(false);
130
button.setBackground(new Color(128, 128, 0));
131
button.setVisible(false);
132
}
133
});
134
135
robot.waitForIdle(500);
136
imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
137
138
SwingUtilities.invokeAndWait(new Runnable() {
139
140
@Override
141
public void run() {
142
button.show();
143
}
144
});
145
146
robot.waitForIdle(500);
147
imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
148
149
SwingUtilities.invokeAndWait(new Runnable() {
150
151
@Override
152
public void run() {
153
button.hide();
154
}
155
});
156
157
if (Util.compareBufferedImages(imageInit, imageShow)) {
158
throw new Exception("Failed to show non-opaque button");
159
}
160
161
robot.waitForIdle(500);
162
imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
163
164
if (!Util.compareBufferedImages(imageInit, imageHide)) {
165
throw new Exception("Failed to hide non-opaque button");
166
}
167
}
168
}
169
170