Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JLabel/6596966/bug6596966.java
41153 views
1
/*
2
* Copyright (c) 2011, 2020, 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 6596966
28
* @summary Some JFileChooser mnemonics do not work with sticky keys
29
* @library ../../regtesthelpers
30
* @library /test/lib
31
* @build Util jdk.test.lib.Platform
32
* @run main bug6596966
33
* @author Pavel Porvatov
34
*/
35
36
import java.awt.EventQueue;
37
import java.awt.Robot;
38
import java.awt.Toolkit;
39
import java.awt.event.KeyEvent;
40
import java.awt.event.InputEvent;
41
import java.util.ArrayList;
42
import javax.swing.JFrame;
43
import javax.swing.JButton;
44
import javax.swing.JComboBox;
45
import javax.swing.JLabel;
46
import javax.swing.JPanel;
47
import javax.swing.SwingUtilities;
48
49
import jdk.test.lib.Platform;
50
51
public class bug6596966 {
52
private static JFrame frame;
53
54
private static JLabel label;
55
private static JButton button;
56
private static JComboBox comboBox;
57
58
public static void main(String[] args) throws Exception {
59
try {
60
Robot robot = new Robot();
61
robot.setAutoDelay(100);
62
63
SwingUtilities.invokeAndWait(new Runnable() {
64
public void run() {
65
button = new JButton("Button");
66
comboBox = new JComboBox();
67
68
label = new JLabel("Label");
69
label.setDisplayedMnemonic('L');
70
label.setLabelFor(comboBox);
71
72
JPanel pnContent = new JPanel();
73
74
pnContent.add(button);
75
pnContent.add(label);
76
pnContent.add(comboBox);
77
78
frame = new JFrame();
79
80
frame.add(pnContent);
81
frame.pack();
82
frame.setVisible(true);
83
}
84
});
85
86
robot.waitForIdle();
87
robot.delay(1000);
88
89
int keyMask = InputEvent.ALT_MASK;
90
if (Platform.isOSX()) {
91
keyMask = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
92
}
93
ArrayList<Integer> keys = Util.getKeyCodesFromKeyMask(keyMask);
94
for (int i = 0; i < keys.size(); ++i) {
95
robot.keyPress(keys.get(i));
96
}
97
98
robot.keyPress(KeyEvent.VK_L);
99
100
robot.waitForIdle();
101
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED,
102
EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));
103
104
robot.waitForIdle();
105
106
try {
107
SwingUtilities.invokeAndWait(new Runnable() {
108
public void run() {
109
if (!comboBox.isFocusOwner()) {
110
throw new RuntimeException("comboBox isn't focus owner");
111
}
112
}
113
});
114
} finally {
115
robot.keyRelease(KeyEvent.VK_L);
116
for (int i = 0; i < keys.size(); ++i) {
117
robot.keyRelease(keys.get(i));
118
}
119
robot.waitForIdle();
120
}
121
} finally {
122
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
123
}
124
}
125
}
126
127