Skip to content

Commit d61765f

Browse files
author
Alisen Chung
committed
8353488: Open some JComboBox bugs 3
Reviewed-by: kizune
1 parent 486a664 commit d61765f

File tree

4 files changed

+326
-0
lines changed

4 files changed

+326
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 1998, 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 javax.swing.JComboBox;
25+
import javax.swing.JFrame;
26+
import javax.swing.JPanel;
27+
28+
/*
29+
* @test
30+
* @bug 4135833
31+
* @summary Tests that JComboBox draws correctly if the first item in list is an empty string
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual bug4135833
35+
*/
36+
37+
public class bug4135833 {
38+
private static final String INSTRUCTIONS = """
39+
Press the combo box. If the popup is readable and appears to be sized properly,
40+
then it passes. The First item is blank intentionally.
41+
""";
42+
43+
public static void main(String[] args) throws Exception {
44+
PassFailJFrame.builder()
45+
.title("Instructions")
46+
.instructions(INSTRUCTIONS)
47+
.columns(50)
48+
.testUI(bug4135833::createTestUI)
49+
.build()
50+
.awaitAndCheck();
51+
}
52+
53+
public static JFrame createTestUI() {
54+
JFrame frame = new JFrame("bug4135833");
55+
JPanel panel = new JPanel();
56+
JComboBox comboBox = new JComboBox(new Object[]{"", "Bob", "Hank", "Joe", "Fred"});
57+
panel.add(comboBox);
58+
frame.add(panel);
59+
frame.pack();
60+
return frame;
61+
}
62+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 1998, 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 javax.swing.JComboBox;
25+
import javax.swing.JFrame;
26+
import javax.swing.JLabel;
27+
import javax.swing.JPanel;
28+
import javax.swing.UIManager;
29+
30+
/*
31+
* @test
32+
* @bug 4171819
33+
* @summary Tests that JComboBox uses a lower bevel border in windows
34+
* @requires (os.family == "windows")
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual bug4171819
38+
*/
39+
40+
public class bug4171819 {
41+
static boolean lafOk = true;
42+
43+
private static final String INSTRUCTIONS = """
44+
This test is for Windows L&F only. If you see
45+
"No Windows L&F installed" label just press "Pass".
46+
47+
Look at the combo box. If the border around it looks like it's
48+
lowered rather than raised, it passes the test.
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.columns(50)
56+
.testUI(bug4171819::createTestUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
public static JFrame createTestUI() {
62+
try {
63+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
64+
System.out.println("succeeded");
65+
} catch (Exception e) {
66+
System.err.println("Couldn't load the Windows Look and Feel");
67+
lafOk = false;
68+
}
69+
70+
JFrame frame = new JFrame("bug4171819");
71+
JPanel panel = new JPanel();
72+
JComboBox comboBox;
73+
74+
if (lafOk) {
75+
comboBox = new JComboBox(new Object[]{
76+
"Coma Berenices",
77+
"Triangulum",
78+
"Camelopardis",
79+
"Cassiopea"});
80+
panel.add(comboBox);
81+
} else {
82+
JLabel label = new JLabel("No Windows L&F installed");
83+
panel.add(label);
84+
}
85+
frame.add(panel);
86+
frame.pack();
87+
return frame;
88+
}
89+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 1999, 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.Robot;
25+
import java.awt.event.KeyEvent;
26+
import javax.swing.BoxLayout;
27+
import javax.swing.JComboBox;
28+
import javax.swing.JFrame;
29+
import javax.swing.SwingUtilities;
30+
31+
/*
32+
* @test
33+
* @bug 4248128 7148092
34+
* @summary Tests that alt+down arrow pulls down JComboBox popup
35+
* @key headful
36+
* @run main bug4248128
37+
*/
38+
39+
public class bug4248128 {
40+
static JFrame frame;
41+
static volatile JComboBox combo;
42+
43+
public static void main(String[] args) throws Exception {
44+
try {
45+
Robot robot = new Robot();
46+
robot.setAutoDelay(250);
47+
SwingUtilities.invokeAndWait(() -> createTestUI());
48+
robot.waitForIdle();
49+
50+
robot.keyPress(KeyEvent.VK_ALT);
51+
robot.keyPress(KeyEvent.VK_DOWN);
52+
robot.keyRelease(KeyEvent.VK_DOWN);
53+
robot.keyRelease(KeyEvent.VK_ALT);
54+
robot.waitForIdle();
55+
56+
SwingUtilities.invokeAndWait(() -> {
57+
if (!combo.isPopupVisible()) {
58+
throw new RuntimeException("Popup did not appear.");
59+
}
60+
});
61+
} finally {
62+
SwingUtilities.invokeAndWait(() -> {
63+
if (frame != null) {
64+
frame.dispose();
65+
}
66+
});
67+
}
68+
}
69+
70+
public static void createTestUI() {
71+
frame = new JFrame("4248128 Test");
72+
Object[] fruits = {"Banana", "Pear", "Apple"};
73+
combo = new JComboBox(fruits);
74+
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS));
75+
frame.add(combo);
76+
frame.pack();
77+
frame.setLocationRelativeTo(null);
78+
frame.setVisible(true);
79+
}
80+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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.FlowLayout;
25+
import java.awt.Point;
26+
import java.awt.Robot;
27+
import java.awt.event.KeyEvent;
28+
import java.awt.event.InputEvent;
29+
import javax.swing.JComboBox;
30+
import javax.swing.JFrame;
31+
import javax.swing.SwingUtilities;
32+
33+
/*
34+
* @test
35+
* @bug 4436376
36+
* @key headful
37+
* @summary Tests that ComboBox items can't be deselected with Ctrl+click
38+
* @run main bug4436376
39+
*/
40+
41+
public class bug4436376 {
42+
static JFrame frame;
43+
static volatile Point p;
44+
static volatile JComboBox combo;
45+
46+
final static int SELECTED_INDEX = 2;
47+
48+
public static void main(String[] args) throws Exception {
49+
try {
50+
Robot robot = new Robot();
51+
robot.setAutoDelay(250);
52+
SwingUtilities.invokeAndWait(() -> createTestUI());
53+
robot.waitForIdle();
54+
55+
SwingUtilities.invokeAndWait(() -> p = combo.getLocationOnScreen());
56+
robot.waitForIdle();
57+
58+
robot.mouseMove(p.x + 10, p.y + 10);
59+
robot.waitForIdle();
60+
61+
robot.keyPress(KeyEvent.VK_CONTROL);
62+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
63+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
64+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
65+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
66+
robot.keyRelease(KeyEvent.VK_CONTROL);
67+
robot.waitForIdle();
68+
69+
SwingUtilities.invokeAndWait(() -> {
70+
if (combo.getSelectedIndex() != SELECTED_INDEX) {
71+
throw new RuntimeException("Failed: selected index has been changed");
72+
}
73+
});
74+
} finally {
75+
SwingUtilities.invokeAndWait(() -> {
76+
if (frame != null) {
77+
frame.dispose();
78+
}
79+
});
80+
}
81+
}
82+
83+
public static void createTestUI() {
84+
frame = new JFrame("bug4436376");
85+
String[] items = new String[]{"One", "Two", "Three", "Four"};
86+
combo = new JComboBox(items);
87+
combo.setSelectedIndex(SELECTED_INDEX);
88+
89+
frame.setLayout(new FlowLayout());
90+
frame.add(combo);
91+
frame.setLocationRelativeTo(null);
92+
frame.pack();
93+
frame.setVisible(true);
94+
}
95+
}

0 commit comments

Comments
 (0)