Skip to content

Commit 1889dac

Browse files
author
Alisen Chung
committed
8353007: Open some JComboBox bugs 2
Reviewed-by: kizune, honkar
1 parent 477da16 commit 1889dac

File tree

4 files changed

+387
-0
lines changed

4 files changed

+387
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 java.awt.BorderLayout;
25+
import java.awt.Point;
26+
import javax.swing.JComboBox;
27+
import javax.swing.JComponent;
28+
import javax.swing.JDesktopPane;
29+
import javax.swing.JFrame;
30+
import javax.swing.JInternalFrame;
31+
import javax.swing.JPanel;
32+
33+
/*
34+
* @test
35+
* @bug 4185024
36+
* @summary Tests that Heavyweight combo boxes on JDesktop work correctly
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual bug4185024
40+
*/
41+
42+
public class bug4185024 {
43+
private static final String INSTRUCTIONS = """
44+
Click on the JComboBox button inside the JInternalFrame to bring up the menu.
45+
Select one of the menu items and verify that the choice is highlighted correctly.
46+
Click and drag the menu's scroll bar down and verify that it causes the menu to scroll down.
47+
48+
Inside JInternalFrame:
49+
This test is for the JComboBox in the JInternalFrame.
50+
To test, please click on the combobox and check the following:
51+
Does the selection in the popup list follow the mouse?
52+
Does the popup list respond to clicking and dragging the scroll bar?
53+
If so, press PASS, otherwise, press FAIL.
54+
""";
55+
56+
public static void main(String[] args) throws Exception {
57+
PassFailJFrame.builder()
58+
.instructions(INSTRUCTIONS)
59+
.columns(50)
60+
.testUI(bug4185024::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
public static JFrame createTestUI() {
66+
JFrame frame = new JFrame("bug4185024");
67+
JPanel p = new JPanel();
68+
p.setLayout(new BorderLayout());
69+
JDesktopPane desktop = new JDesktopPane();
70+
p.add(desktop);
71+
frame.add(p);
72+
73+
JComboBox months = new JComboBox();
74+
months.addItem("January");
75+
months.addItem("February");
76+
months.addItem("March");
77+
months.addItem("April");
78+
months.addItem("May");
79+
months.addItem("June");
80+
months.addItem("July");
81+
months.addItem("August");
82+
months.addItem("September");
83+
months.addItem("October");
84+
months.addItem("November");
85+
months.addItem("December");
86+
months.getAccessibleContext().setAccessibleName("Months");
87+
months.getAccessibleContext().setAccessibleDescription("Choose a month of the year");
88+
89+
// Set this to true and the popup works correctly...
90+
months.setLightWeightPopupEnabled(false);
91+
92+
addFrame("Months", desktop, months);
93+
94+
frame.setSize(300, 300);
95+
return frame;
96+
}
97+
98+
private static void addFrame(String title, JDesktopPane desktop, JComponent component) {
99+
JInternalFrame jf = new JInternalFrame(title);
100+
Point newPos = new Point(20, 20);
101+
jf.setResizable(true);
102+
jf.add(component);
103+
jf.setLocation(newPos);
104+
desktop.add(jf);
105+
106+
jf.pack();
107+
jf.show();
108+
}
109+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 javax.swing.JComboBox;
25+
import javax.swing.JFrame;
26+
import javax.swing.JPanel;
27+
import javax.swing.UIManager;
28+
29+
/*
30+
* @test
31+
* @bug 4201964
32+
* @summary Tests that JComboBox's arrow button isn't drawn too wide in Windows Look&Feel
33+
* @requires (os.family == "windows")
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual bug4201964
37+
*/
38+
39+
public class bug4201964 {
40+
private static final String INSTRUCTIONS = """
41+
Does the arrow look too large? If not, it passes.
42+
""";
43+
44+
public static void main(String[] args) throws Exception {
45+
try {
46+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
47+
} catch (Exception e) {
48+
PassFailJFrame.forceFail("Couldn't load the Windows look and feel.");
49+
}
50+
51+
PassFailJFrame.builder()
52+
.instructions(INSTRUCTIONS)
53+
.rows(8)
54+
.columns(30)
55+
.testUI(bug4201964::createTestUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
public static JFrame createTestUI() {
61+
JFrame frame = new JFrame("bug4201964");
62+
JPanel panel = new JPanel();
63+
JComboBox comboBox;
64+
65+
comboBox = new JComboBox(new Object[]{
66+
"Coma Berenices",
67+
"Triangulum",
68+
"Camelopardis",
69+
"Cassiopea"});
70+
71+
panel.add(comboBox);
72+
73+
frame.add(panel);
74+
frame.pack();
75+
return frame;
76+
}
77+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.BorderLayout;
25+
import javax.swing.JComboBox;
26+
import javax.swing.JFrame;
27+
import javax.swing.UIManager;
28+
29+
/*
30+
* @test
31+
* @bug 4249732
32+
* @requires (os.family == "windows")
33+
* @summary Tests that Windows editable combo box selects text picked from its list
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual bug4249732
37+
*/
38+
39+
public class bug4249732 {
40+
private static final String INSTRUCTIONS = """
41+
Click on combo box arrow button to open its dropdown list, and
42+
select an item from there. The text in the combo box editor should
43+
be selected, otherwise test fails.
44+
""";
45+
46+
public static void main(String[] args) throws Exception {
47+
try {
48+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
49+
} catch (Exception e) {
50+
PassFailJFrame.forceFail("Couldn't load the Windows look and feel.");
51+
}
52+
53+
PassFailJFrame.builder()
54+
.instructions(INSTRUCTIONS)
55+
.rows(8)
56+
.columns(40)
57+
.testUI(bug4249732::createTestUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
public static JFrame createTestUI() {
63+
JFrame frame = new JFrame("bug4249732");
64+
65+
JComboBox cb = new JComboBox(new Object[]{"foo", "bar", "baz"});
66+
cb.setEditable(true);
67+
68+
frame.add(cb, BorderLayout.NORTH);
69+
frame.pack();
70+
return frame;
71+
}
72+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2000, 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.DefaultCellEditor;
25+
import javax.swing.JComboBox;
26+
import javax.swing.JFrame;
27+
import javax.swing.JScrollPane;
28+
import javax.swing.JTable;
29+
import javax.swing.table.AbstractTableModel;
30+
31+
/*
32+
* @test
33+
* @bug 4368848
34+
* @summary Tests that mouse wheel events cancel popups
35+
* @library /java/awt/regtesthelpers
36+
* @build PassFailJFrame
37+
* @run main/manual bug4368848
38+
*/
39+
40+
public class bug4368848 {
41+
static final String[] names = {"First Name", "Last Name", "Veggy"};
42+
static Object[][] data = {
43+
{"Mark", "Andrews", false},
44+
{"Tom", "Ball", false},
45+
{"Alan", "Chung", false},
46+
{"Jeff", "Dinkins", false},
47+
{"Amy", "Fowler", false},
48+
{"Brian", "Gerhold", false},
49+
{"James", "Gosling", false},
50+
{"David", "Karlton", false},
51+
{"Dave", "Kloba", false},
52+
{"Peter", "Korn", false},
53+
{"Phil", "Milne", false},
54+
{"Dave", "Moore", false},
55+
{"Hans", "Muller", false},
56+
{"Rick", "Levenson", false},
57+
{"Tim", "Prinzing", false},
58+
{"Chester", "Rose", false},
59+
{"Ray", "Ryan", false},
60+
{"Georges", "Saab", false},
61+
{"Willie", "Walker", false},
62+
{"Kathy", "Walrath", false},
63+
{"Arnaud", "Weber", false}
64+
};
65+
66+
private static final String INSTRUCTIONS = """
67+
Click any cell in the 'Veggy' column, so that combo box appears.
68+
Make sure mouse pointer is over the table, but _not_ over the combo
69+
box. Try scrolling the table using the mouse wheel. The combo popup
70+
should disappear. If it stays visible, test fails.
71+
""";
72+
73+
public static void main(String[] args) throws Exception {
74+
PassFailJFrame.builder()
75+
.instructions(INSTRUCTIONS)
76+
.columns(50)
77+
.testUI(bug4368848::createTestUI)
78+
.build()
79+
.awaitAndCheck();
80+
}
81+
82+
public static JFrame createTestUI() {
83+
JFrame frame = new JFrame("bug4368848");
84+
ExampleTableModel dataModel = new ExampleTableModel();
85+
86+
JComboBox _editor = new JComboBox();
87+
_editor.addItem(false);
88+
_editor.addItem(true);
89+
90+
JTable tableView = new JTable(dataModel);
91+
tableView.setDefaultEditor(Boolean.class, new DefaultCellEditor(_editor));
92+
93+
frame.add(new JScrollPane(tableView));
94+
frame.setSize(200, 200);
95+
return frame;
96+
}
97+
98+
static class ExampleTableModel extends AbstractTableModel {
99+
// These methods always need to be implemented.
100+
@Override
101+
public int getColumnCount() {
102+
return names.length;
103+
}
104+
105+
@Override
106+
public int getRowCount() {
107+
return data.length;
108+
}
109+
110+
public Object getValueAt(int row, int col) {
111+
return data[row][col];
112+
}
113+
114+
@Override
115+
public boolean isCellEditable(int row, int col) {
116+
return true;
117+
}
118+
119+
@Override
120+
public String getColumnName(int column) {
121+
return names[column];
122+
}
123+
124+
@Override
125+
public Class getColumnClass(int col) {
126+
return getValueAt(0, col).getClass();
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)