Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComboBox/6559152/bug6559152.java
38854 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
/* @test
24
@bug 6559152
25
@summary Checks that you can select an item in JComboBox with keyboard
26
when it is a JTable cell editor.
27
@author Mikhail Lapshin
28
@library ../../../../lib/testlibrary
29
@build ExtendedRobot
30
@run main bug6559152
31
*/
32
33
import javax.swing.*;
34
import javax.swing.table.DefaultTableModel;
35
import java.awt.*;
36
import java.awt.event.KeyEvent;
37
38
public class bug6559152 {
39
private JFrame frame;
40
private JComboBox cb;
41
private ExtendedRobot robot;
42
43
public static void main(String[] args) throws Exception {
44
final bug6559152 test = new bug6559152();
45
try {
46
SwingUtilities.invokeAndWait(new Runnable() {
47
public void run() {
48
test.setupUI();
49
}
50
});
51
test.test();
52
} finally {
53
if (test.frame != null) {
54
test.frame.dispose();
55
}
56
}
57
}
58
59
private void setupUI() {
60
frame = new JFrame();
61
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
62
63
DefaultTableModel model = new DefaultTableModel(1, 1);
64
JTable table = new JTable(model);
65
66
cb = new JComboBox(new String[]{"one", "two", "three"});
67
cb.setEditable(true);
68
table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb));
69
frame.add(cb);
70
71
frame.pack();
72
frame.setLocationRelativeTo(null);
73
frame.setVisible(true);
74
}
75
76
private void test() throws Exception {
77
robot = new ExtendedRobot();
78
robot.waitForIdle();
79
testImpl();
80
robot.waitForIdle();
81
checkResult();
82
}
83
84
private void testImpl() throws Exception {
85
robot.type(KeyEvent.VK_DOWN);
86
robot.waitForIdle();
87
robot.type(KeyEvent.VK_DOWN);
88
robot.waitForIdle();
89
robot.type(KeyEvent.VK_ENTER);
90
}
91
92
private void checkResult() {
93
if (cb.getSelectedItem().equals("two")) {
94
System.out.println("Test passed");
95
} else {
96
System.out.println("Test failed");
97
throw new RuntimeException("Cannot select an item " +
98
"from popup with the ENTER key.");
99
}
100
}
101
}
102
103