Skip to content

Commit 3195d3d

Browse files
committedOct 25, 2024
8322754: click JComboBox when dialog about to close causes IllegalComponentStateException
Backport-of: e44276989fc6358065412be7567d0141c84f1282
1 parent 5daf066 commit 3195d3d

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed
 

‎src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -921,7 +921,7 @@ public void mousePressed(MouseEvent e) {
921921
if (e.getSource() == list) {
922922
return;
923923
}
924-
if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled())
924+
if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled() || !comboBox.isShowing())
925925
return;
926926

927927
if ( comboBox.isEditable() ) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2024, 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.JButton;
25+
import javax.swing.JComboBox;
26+
import javax.swing.JFrame;
27+
import javax.swing.SwingUtilities;
28+
29+
/*
30+
* @test
31+
* @bug 8322754
32+
* @summary Verifies clicking JComboBox during frame closure causes Exception
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual ComboPopupBug
36+
*/
37+
38+
public class ComboPopupBug {
39+
private static final String instructionsText = """
40+
This test is used to verify that clicking on JComboBox
41+
when frame containing it is about to close should not
42+
cause IllegalStateException.
43+
44+
A JComboBox is shown with Close button at the bottom.
45+
Click on Close and then click on JComboBox arrow button
46+
to try to show combobox popup.
47+
If IllegalStateException is thrown, test will automatically Fail
48+
otherwise click Pass. """;
49+
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
52+
.title("ComboPopup Instructions")
53+
.instructions(instructionsText)
54+
.testTimeOut(5)
55+
.rows(10)
56+
.columns(35)
57+
.build();
58+
59+
SwingUtilities.invokeAndWait(() -> {
60+
JFrame frame = new JFrame("ComboPopup");
61+
62+
JComboBox cb = new JComboBox();
63+
cb.setEditable(true);
64+
cb.addItem("test");
65+
cb.addItem("test2");
66+
cb.addItem("test3");
67+
frame.getContentPane().add(cb, "North");
68+
69+
JButton b = new JButton("Close");
70+
b.addActionListener(
71+
(e)->{
72+
try {
73+
Thread.sleep(3000);
74+
}
75+
catch (Exception ex) {
76+
}
77+
frame.setVisible(false);
78+
79+
});
80+
frame.getContentPane().add(b, "South");
81+
frame.setSize(200, 200);
82+
83+
PassFailJFrame.addTestWindow(frame);
84+
PassFailJFrame.positionTestWindow(frame,
85+
PassFailJFrame.Position.HORIZONTAL);
86+
87+
frame.setVisible(true);
88+
});
89+
90+
passFailJFrame.awaitAndCheck();
91+
}
92+
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Oct 25, 2024

@openjdk-notifier[bot]
Please sign in to comment.