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/JRadioButton/8041561/bug8041561.java
38854 views
1
/*
2
* Copyright (c) 2014, 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
import java.awt.AWTException;
25
import java.awt.Color;
26
import java.awt.Point;
27
import java.awt.Robot;
28
import javax.swing.JFrame;
29
import javax.swing.JPanel;
30
import javax.swing.JRadioButton;
31
import javax.swing.SwingUtilities;
32
import javax.swing.UIManager;
33
import javax.swing.UnsupportedLookAndFeelException;
34
import javax.swing.plaf.metal.DefaultMetalTheme;
35
import javax.swing.plaf.metal.MetalLookAndFeel;
36
37
/**
38
* @test
39
* @bug 8041561
40
* @author Alexander Scherbatiy
41
* @summary Inconsistent opacity behaviour between JCheckBox and JRadioButton
42
* @run main bug8041561
43
*/
44
public class bug8041561 {
45
46
private static JRadioButton radioButton;
47
48
public static void main(String[] args) throws Exception {
49
SwingUtilities.invokeAndWait(new Runnable() {
50
51
@Override
52
public void run() {
53
try {
54
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
55
UIManager.setLookAndFeel(new MetalLookAndFeel());
56
createAndShowGUI();
57
} catch (UnsupportedLookAndFeelException e) {
58
throw new RuntimeException(e);
59
}
60
}
61
});
62
63
new Robot().waitForIdle();
64
Thread.sleep(500);
65
66
SwingUtilities.invokeAndWait(new Runnable() {
67
68
@Override
69
public void run() {
70
try {
71
Point point = radioButton.getLocationOnScreen();
72
int x = (int) point.getX() + radioButton.getWidth() / 2;
73
int y = (int) point.getY() + radioButton.getHeight() / 2;
74
75
Robot robot = new Robot();
76
Color color = robot.getPixelColor(x, y);
77
if (!Color.BLUE.equals(color)) {
78
throw new RuntimeException("JRadioButton is opaque");
79
}
80
} catch (AWTException e) {
81
throw new RuntimeException(e);
82
}
83
}
84
});
85
86
}
87
88
private static void createAndShowGUI() {
89
JFrame frame = new JFrame();
90
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
91
frame.setBackground(Color.BLUE);
92
radioButton = new JRadioButton();
93
radioButton.setOpaque(false);
94
JPanel panel = new JPanel();
95
panel.setBackground(Color.BLUE);
96
panel.add(radioButton);
97
frame.getContentPane().add(panel);
98
frame.pack();
99
frame.setVisible(true);
100
}
101
}
102
103