Skip to content

Commit 0b2a2f3

Browse files
author
Alisen Chung
committed
8353685: Open some JComboBox bugs 4
Reviewed-by: honkar, kizune
1 parent 17b080b commit 0b2a2f3

File tree

3 files changed

+255
-0
lines changed

3 files changed

+255
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
import java.awt.event.ActionListener;
25+
import javax.swing.JButton;
26+
import javax.swing.JComboBox;
27+
import javax.swing.JFrame;
28+
import javax.swing.JLabel;
29+
import javax.swing.JPanel;
30+
31+
/*
32+
* @test
33+
* @bug 4212498
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual bug4212498
37+
*/
38+
39+
public class bug4212498 {
40+
static JPanel panel = new JPanel();
41+
static JComboBox comboBox = new JComboBox(new Object[]{
42+
"Coma Berenices",
43+
"Triangulum",
44+
"Camelopardis",
45+
"Cassiopea"});
46+
47+
private static final String INSTRUCTIONS = """
48+
Edit the value in the text field (without using the popup)
49+
and then press the tab key. If the number doesn't increase,
50+
then test fails.
51+
52+
Also, try tabbing out without making a change. The number
53+
should NOT increase unless the user changes something.
54+
""";
55+
56+
public static void main(String[] args) throws Exception {
57+
PassFailJFrame.builder()
58+
.title("Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.columns(50)
61+
.testUI(bug4212498::createTestUI)
62+
.build()
63+
.awaitAndCheck();
64+
}
65+
66+
public static JFrame createTestUI() {
67+
JFrame frame = new JFrame("bug4212498");
68+
comboBox.setEditable(true);
69+
70+
final JLabel label = new JLabel("0");
71+
72+
ActionListener actionListener =
73+
e -> label.setText("" + (Integer.parseInt(label.getText()) + 1));
74+
75+
comboBox.addActionListener(actionListener);
76+
77+
panel.add(comboBox);
78+
panel.add(label);
79+
panel.add(new JButton("B"));
80+
81+
frame.getContentPane().add(panel);
82+
frame.pack();
83+
frame.setLocationRelativeTo(null);
84+
return frame;
85+
}
86+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
import java.awt.BorderLayout;
25+
import java.awt.Robot;
26+
import java.awt.event.KeyEvent;
27+
import javax.swing.JComboBox;
28+
import javax.swing.JFrame;
29+
import javax.swing.SwingUtilities;
30+
31+
/*
32+
* @test
33+
* @bug 4459267
34+
* @summary Tests that pressing PageUp in combo popup list doesn't cause
35+
* stack overflow
36+
* @key headful
37+
* @run main bug4459267
38+
*/
39+
40+
public class bug4459267 {
41+
static JFrame frame;
42+
43+
public static void main(String[] args) throws Exception {
44+
try {
45+
Robot robot = new Robot();
46+
robot.setAutoDelay(250);
47+
48+
SwingUtilities.invokeAndWait(() -> createTestUI());
49+
robot.waitForIdle();
50+
robot.delay(1000);
51+
52+
robot.keyPress(KeyEvent.VK_PAGE_UP);
53+
robot.keyRelease(KeyEvent.VK_PAGE_UP);
54+
robot.waitForIdle();
55+
} finally {
56+
SwingUtilities.invokeAndWait(() -> {
57+
if (frame != null) {
58+
frame.dispose();
59+
}
60+
});
61+
}
62+
}
63+
64+
public static void createTestUI() {
65+
frame = new JFrame("bug4459267");
66+
JComboBox jcmb = new JComboBox();
67+
jcmb.addItem("JComobo1");
68+
jcmb.addItem("Item2");
69+
jcmb.addItem("Item3");
70+
frame.getContentPane().add(jcmb, BorderLayout.NORTH);
71+
frame.pack();
72+
frame.setLocationRelativeTo(null);
73+
frame.setVisible(true);
74+
}
75+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
import java.awt.Point;
25+
import java.awt.Robot;
26+
import java.awt.event.InputEvent;
27+
import java.awt.event.KeyEvent;
28+
import javax.swing.JComboBox;
29+
import javax.swing.JFrame;
30+
import javax.swing.SwingUtilities;
31+
32+
/*
33+
* @test
34+
* @bug 4519269
35+
* @summary Tests that DefaultKeySelectionManager doesn't throw NPE
36+
* @key headful
37+
* @run main bug4519269
38+
*/
39+
40+
public class bug4519269 {
41+
static JFrame frame;
42+
static JComboBox combo;
43+
static Point p;
44+
static Object[] data = {new CustomString("Item 1"), new CustomString("Item 2"),
45+
new CustomString("Item 3"), new CustomString("Item 4")};
46+
47+
public static void main(String[] args) throws Exception {
48+
try {
49+
Robot robot = new Robot();
50+
robot.setAutoDelay(250);
51+
52+
SwingUtilities.invokeAndWait(() -> createTestUI());
53+
robot.waitForIdle();
54+
robot.delay(1000);
55+
56+
SwingUtilities.invokeAndWait(() -> p = combo.getLocationOnScreen());
57+
robot.mouseMove(p.x + 5, p.y + 5);
58+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
59+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
60+
robot.waitForIdle();
61+
62+
robot.keyPress(KeyEvent.VK_SHIFT);
63+
robot.keyRelease(KeyEvent.VK_SHIFT);
64+
robot.waitForIdle();
65+
} finally {
66+
SwingUtilities.invokeAndWait(() -> {
67+
if (frame != null) {
68+
frame.dispose();
69+
}
70+
});
71+
}
72+
}
73+
74+
public static void createTestUI() {
75+
frame = new JFrame("bug4519269");
76+
combo = new JComboBox(data);
77+
frame.getContentPane().add(combo);
78+
frame.pack();
79+
frame.setLocationRelativeTo(null);
80+
frame.setVisible(true);
81+
}
82+
83+
static class CustomString {
84+
String string;
85+
86+
public CustomString(String s) {
87+
string = s;
88+
}
89+
90+
public String toString() {
91+
return null;
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)