Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/DefaultButtonModel/DefaultButtonModelCrashTest.java
66644 views
1
/*
2
* Copyright (c) 2017, 2021, 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
* @bug 8182577
27
* @summary Verifies if moving focus to JToggleButton with DefaultButtonModel
28
* that is added to a ButtonGroup doesn't throw ClassCastException
29
* @key headful
30
* @run main DefaultButtonModelCrashTest
31
*/
32
33
import java.awt.BorderLayout;
34
import java.awt.Robot;
35
import java.awt.event.KeyEvent;
36
import javax.swing.ButtonModel;
37
import javax.swing.DefaultButtonModel;
38
import javax.swing.JCheckBox;
39
import javax.swing.JFrame;
40
import javax.swing.JPanel;
41
import javax.swing.JTextField;
42
import javax.swing.SwingUtilities;
43
44
public class DefaultButtonModelCrashTest {
45
private JFrame frame = null;
46
47
public static void main(String[] args) throws Exception {
48
new DefaultButtonModelCrashTest();
49
}
50
51
public DefaultButtonModelCrashTest() throws Exception {
52
try {
53
Robot robot = new Robot();
54
robot.setAutoDelay(200);
55
SwingUtilities.invokeAndWait(() -> go());
56
robot.waitForIdle();
57
robot.delay(1000);
58
robot.keyPress(KeyEvent.VK_TAB);
59
robot.keyRelease(KeyEvent.VK_TAB);
60
robot.delay(100);
61
robot.keyPress(KeyEvent.VK_TAB);
62
robot.keyRelease(KeyEvent.VK_TAB);
63
} finally {
64
SwingUtilities.invokeAndWait(() -> {
65
if (frame != null) {
66
frame.dispose();
67
}
68
});
69
}
70
}
71
72
private void go() {
73
frame = new JFrame();
74
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75
76
ButtonModel model = new DefaultButtonModel();
77
JCheckBox check = new JCheckBox("a bit broken");
78
check.setModel(model);
79
80
JPanel panel = new JPanel(new BorderLayout());
81
panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
82
panel.add(check);
83
84
frame.getContentPane().add(panel);
85
frame.setLocationRelativeTo(null);
86
frame.pack();
87
frame.setVisible(true);
88
}
89
}
90
91