Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/6559152/bug6559152.java
41153 views
1
/*
2
* Copyright (c) 2011, 2014, 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 6559152
28
* @summary Checks that you can select an item in JComboBox with keyboard
29
* when it is a JTable cell editor.
30
* @run main bug6559152
31
*/
32
33
import javax.swing.DefaultCellEditor;
34
import javax.swing.JComponent;
35
import javax.swing.JFrame;
36
import javax.swing.JComboBox;
37
import javax.swing.SwingUtilities;
38
import javax.swing.table.DefaultTableModel;
39
import javax.swing.JTable;
40
import java.awt.Point;
41
import java.awt.event.KeyEvent;
42
import java.awt.event.InputEvent;
43
import java.awt.Robot;
44
45
public class bug6559152 {
46
private static JFrame frame;
47
private static JComboBox cb;
48
private static Robot robot;
49
private static Point p = null;
50
51
public static void main(String[] args) throws Exception {
52
robot = new Robot();
53
robot.setAutoDelay(100);
54
try {
55
SwingUtilities.invokeAndWait(() -> setupUI());
56
blockTillDisplayed(cb);
57
robot.waitForIdle();
58
robot.delay(1000);
59
test();
60
} finally {
61
if (frame != null) {
62
SwingUtilities.invokeAndWait(() -> frame.dispose());
63
}
64
}
65
}
66
67
static void blockTillDisplayed(JComponent comp) throws Exception {
68
while (p == null) {
69
try {
70
SwingUtilities.invokeAndWait(() -> {
71
p = comp.getLocationOnScreen();
72
});
73
} catch (IllegalStateException e) {
74
try {
75
Thread.sleep(1000);
76
} catch (InterruptedException ie) {
77
}
78
}
79
}
80
}
81
82
private static void setupUI() {
83
frame = new JFrame();
84
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
85
86
DefaultTableModel model = new DefaultTableModel(1, 1);
87
JTable table = new JTable(model);
88
89
cb = new JComboBox(new String[]{"one", "two", "three"});
90
cb.setEditable(true);
91
table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb));
92
frame.add(cb);
93
94
frame.pack();
95
frame.setLocationRelativeTo(null);
96
frame.setVisible(true);
97
}
98
99
private static void test() throws Exception {
100
robot.mouseMove(p.x, p.y);
101
robot.waitForIdle();
102
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
103
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
104
robot.waitForIdle();
105
testImpl();
106
checkResult();
107
}
108
109
private static void testImpl() throws Exception {
110
robot.keyPress(KeyEvent.VK_DOWN);
111
robot.keyRelease(KeyEvent.VK_DOWN);
112
robot.waitForIdle();
113
robot.keyPress(KeyEvent.VK_DOWN);
114
robot.keyRelease(KeyEvent.VK_DOWN);
115
robot.waitForIdle();
116
robot.keyPress(KeyEvent.VK_ENTER);
117
robot.keyRelease(KeyEvent.VK_ENTER);
118
robot.waitForIdle();
119
}
120
121
private static void checkResult() {
122
if (cb.getSelectedItem().equals("two")) {
123
System.out.println("Test passed");
124
} else {
125
System.out.println("Test failed");
126
throw new RuntimeException("Cannot select an item " +
127
"from popup with the ENTER key.");
128
}
129
}
130
}
131
132