Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/4624207/bug4624207.java
41153 views
1
/*
2
* Copyright (c) 2011, 2018, 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 4624207
28
* @summary JTabbedPane mnemonics don't work from outside the tabbed pane
29
* @author Oleg Mokhovikov
30
* @library /test/lib
31
* @library ../../regtesthelpers
32
* @build Util jdk.test.lib.Platform
33
* @run main bug4624207
34
*/
35
import javax.swing.*;
36
import javax.swing.event.ChangeEvent;
37
import javax.swing.event.ChangeListener;
38
import java.awt.*;
39
import java.awt.event.FocusEvent;
40
import java.awt.event.FocusListener;
41
import java.awt.event.KeyEvent;
42
43
import jdk.test.lib.Platform;
44
45
public class bug4624207 implements ChangeListener, FocusListener {
46
47
private static volatile boolean stateChanged = false;
48
private static volatile boolean focusGained = false;
49
private static JTextField txtField;
50
private static JTabbedPane tab;
51
private static Object listener;
52
private static JFrame frame;
53
54
public void stateChanged(ChangeEvent e) {
55
System.out.println("stateChanged called");
56
stateChanged = true;
57
}
58
59
public void focusGained(FocusEvent e) {
60
System.out.println("focusGained called");
61
focusGained = true;
62
}
63
64
public void focusLost(FocusEvent e) {
65
System.out.println("focusLost called");
66
focusGained = false;
67
}
68
69
public static void main(String[] args) throws Exception {
70
try {
71
Robot robot = new Robot();
72
robot.setAutoDelay(50);
73
74
SwingUtilities.invokeAndWait(new Runnable() {
75
76
public void run() {
77
createAndShowGUI();
78
}
79
});
80
81
robot.waitForIdle();
82
83
SwingUtilities.invokeAndWait(new Runnable() {
84
85
public void run() {
86
txtField.requestFocus();
87
}
88
});
89
90
robot.waitForIdle();
91
92
if (!focusGained) {
93
throw new RuntimeException("Couldn't gain focus for text field");
94
}
95
96
SwingUtilities.invokeAndWait(new Runnable() {
97
98
public void run() {
99
tab.addChangeListener((ChangeListener) listener);
100
txtField.removeFocusListener((FocusListener) listener);
101
}
102
});
103
104
robot.waitForIdle();
105
106
if (Platform.isOSX()) {
107
Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
108
} else {
109
Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
110
}
111
112
robot.waitForIdle();
113
114
if (!stateChanged || tab.getSelectedIndex() != 1) {
115
throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
116
}
117
} finally {
118
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
119
}
120
}
121
122
private static void createAndShowGUI() {
123
tab = new JTabbedPane();
124
tab.add("Tab1", new JButton("Button1"));
125
tab.add("Tab2", new JButton("Button2"));
126
tab.setMnemonicAt(0, KeyEvent.VK_T);
127
tab.setMnemonicAt(1, KeyEvent.VK_B);
128
129
frame = new JFrame();
130
frame.getContentPane().add(tab, BorderLayout.CENTER);
131
txtField = new JTextField();
132
frame.getContentPane().add(txtField, BorderLayout.NORTH);
133
listener = new bug4624207();
134
txtField.addFocusListener((FocusListener) listener);
135
frame.pack();
136
frame.setVisible(true);
137
}
138
}
139
140