Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JRadioButton/8075609/bug8075609.java
41153 views
1
/*
2
* Copyright (c) 2015, 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
* @test
26
* @key headful
27
* @library ../../regtesthelpers
28
* @build Util
29
* @bug 8075609
30
* @summary IllegalArgumentException when transferring focus from JRadioButton using tab
31
* @author Vivi An
32
* @run main bug8075609
33
*/
34
35
import javax.swing.*;
36
import javax.swing.event.*;
37
import java.awt.event.*;
38
import java.awt.*;
39
40
public class bug8075609 {
41
private static Robot robot;
42
private static JTextField textField;
43
private static JFrame mainFrame;
44
45
public static void main(String args[]) throws Throwable {
46
try {
47
SwingUtilities.invokeAndWait(new Runnable() {
48
public void run() {
49
createAndShowGUI();
50
}
51
});
52
53
robot = new Robot();
54
Thread.sleep(100);
55
56
robot.setAutoDelay(100);
57
58
// Radio button group tab key test
59
runTest1();
60
} finally {
61
if (mainFrame != null) SwingUtilities.invokeAndWait(() -> mainFrame.dispose());
62
}
63
}
64
65
private static void createAndShowGUI() {
66
mainFrame = new JFrame("Bug 8075609 - 1 test");
67
68
JPanel rootPanel = new JPanel();
69
rootPanel.setLayout(new BorderLayout());
70
71
JPanel formPanel = new JPanel();
72
formPanel.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
73
formPanel.setFocusCycleRoot(true);
74
75
JRadioButton option1 = new JRadioButton("Option 1", true);
76
JRadioButton option2 = new JRadioButton("Option 2");
77
78
ButtonGroup radioButtonGroup = new ButtonGroup();
79
radioButtonGroup.add(option1);
80
radioButtonGroup.add(option2);
81
82
formPanel.add(option1);
83
formPanel.add(option2);
84
textField = new JTextField("Another focusable component");
85
formPanel.add(textField);
86
87
rootPanel.add(formPanel, BorderLayout.CENTER);
88
89
JButton okButton = new JButton("OK");
90
rootPanel.add(okButton, BorderLayout.SOUTH);
91
92
mainFrame.add(rootPanel);
93
mainFrame.pack();
94
mainFrame.setVisible(true);
95
mainFrame.toFront();
96
}
97
98
// Radio button Group as a single component when traversing through tab key
99
private static void runTest1() throws Exception{
100
hitKey(robot, KeyEvent.VK_TAB);
101
102
robot.delay(1000 );
103
SwingUtilities.invokeAndWait(new Runnable() {
104
public void run() {
105
if (!textField.hasFocus()) {
106
System.out.println("Radio Button Group Go To Next Component through Tab Key failed");
107
throw new RuntimeException("Focus is not on textField as Expected");
108
}
109
}
110
});
111
}
112
113
private static void hitKey(Robot robot, int keycode) {
114
robot.keyPress(keycode);
115
robot.keyRelease(keycode);
116
robot.waitForIdle();
117
}
118
}
119
120