Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JButton/4368790/bug4368790.java
41153 views
1
/*
2
* Copyright (c) 2009, 2010, 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
* @bug 4368790 8213123
28
* @summary JButton stays pressed when focus stolen
29
* @run main bug4368790
30
*/
31
32
import java.awt.Robot;
33
import java.awt.event.KeyEvent;
34
import java.awt.FlowLayout;
35
import javax.swing.JButton;
36
import javax.swing.JFrame;
37
import javax.swing.SwingUtilities;
38
import javax.swing.UIManager;
39
import javax.swing.UnsupportedLookAndFeelException;
40
41
public class bug4368790 {
42
private static JButton b1;
43
private static JFrame frame;
44
45
private static void createGui() {
46
frame = new JFrame();
47
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
48
frame.setLayout(new FlowLayout());
49
50
b1 = new JButton("Button1");
51
frame.add(b1);
52
frame.add(new JButton("Button2"));
53
54
frame.setSize(200, 200);
55
frame.setLocationRelativeTo(null);
56
frame.setVisible(true);
57
b1.requestFocus();
58
}
59
60
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
61
try {
62
UIManager.setLookAndFeel(laf.getClassName());
63
} catch (UnsupportedLookAndFeelException ignored) {
64
System.out.println("Unsupported L&F: " + laf.getClassName());
65
} catch (ClassNotFoundException | InstantiationException
66
| IllegalAccessException e) {
67
throw new RuntimeException(e);
68
}
69
}
70
71
public static void main(String[] args) throws Exception {
72
Robot robot = new Robot();
73
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
74
System.out.println("Testing L&F: " + laf);
75
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
76
77
try {
78
robot.setAutoDelay(50);
79
SwingUtilities.invokeAndWait(new Runnable() {
80
public void run() {
81
bug4368790.createGui();
82
}
83
});
84
robot.waitForIdle();
85
robot.keyPress(KeyEvent.VK_SPACE);
86
robot.keyPress(KeyEvent.VK_TAB);
87
robot.keyRelease(KeyEvent.VK_TAB);
88
robot.keyRelease(KeyEvent.VK_SPACE);
89
robot.waitForIdle();
90
if (b1.getModel().isPressed()) {
91
throw new RuntimeException("The button is unexpectedly pressed");
92
}
93
} finally {
94
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
95
}
96
robot.delay(1000);
97
}
98
}
99
}
100
101