Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JRadioButton/8041561/bug8041561.java
41154 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
* @key headful
40
* @bug 8041561
41
* @author Alexander Scherbatiy
42
* @summary Inconsistent opacity behaviour between JCheckBox and JRadioButton
43
* @run main bug8041561
44
*/
45
public class bug8041561 {
46
47
private static JRadioButton radioButton;
48
private static JFrame frame;
49
50
public static void main(String[] args) throws Exception {
51
try {
52
SwingUtilities.invokeAndWait(new Runnable() {
53
54
@Override
55
public void run() {
56
try {
57
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
58
UIManager.setLookAndFeel(new MetalLookAndFeel());
59
createAndShowGUI();
60
} catch (UnsupportedLookAndFeelException e) {
61
throw new RuntimeException(e);
62
}
63
}
64
});
65
66
new Robot().waitForIdle();
67
Thread.sleep(500);
68
69
SwingUtilities.invokeAndWait(new Runnable() {
70
71
@Override
72
public void run() {
73
try {
74
Point point = radioButton.getLocationOnScreen();
75
int x = (int) point.getX() + radioButton.getWidth() / 2;
76
int y = (int) point.getY() + radioButton.getHeight() / 2;
77
78
Robot robot = new Robot();
79
Color color = robot.getPixelColor(x, y);
80
if (!Color.BLUE.equals(color)) {
81
throw new RuntimeException("JRadioButton is opaque");
82
}
83
} catch (AWTException e) {
84
throw new RuntimeException(e);
85
}
86
}
87
});
88
} finally {
89
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
90
}
91
}
92
93
private static void createAndShowGUI() {
94
frame = new JFrame();
95
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
96
frame.setBackground(Color.BLUE);
97
radioButton = new JRadioButton();
98
radioButton.setOpaque(false);
99
JPanel panel = new JPanel();
100
panel.setBackground(Color.BLUE);
101
panel.add(radioButton);
102
frame.getContentPane().add(panel);
103
frame.pack();
104
frame.setVisible(true);
105
}
106
}
107
108