8290399: [macos] Aqua LAF does not fire an action event if combo box … · openjdk/jdk11u-dev@05bb69d (original) (raw)
``
1
`+
/*
`
``
2
`+
- Copyright (c) 2022, 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
`+
/*
`
``
25
`+
- @test
`
``
26
`+
- @bug 8290399
`
``
27
`+
- @requires (os.family == "mac")
`
``
28
`+
- @library /java/awt/regtesthelpers
`
``
29
`+
- @build PassFailJFrame
`
``
30
`+
- @summary Tests if AquaL&F fire actionevent if combobox menu is displayed.
`
``
31
`+
- @run main/manual JComboBoxActionEvent
`
``
32
`+
*/
`
``
33
+
``
34
`+
import java.awt.FlowLayout;
`
``
35
+
``
36
`+
import javax.swing.JComboBox;
`
``
37
`+
import javax.swing.JFrame;
`
``
38
`+
import javax.swing.JLabel;
`
``
39
`+
import javax.swing.JOptionPane;
`
``
40
`+
import javax.swing.JPanel;
`
``
41
`+
import javax.swing.SwingUtilities;
`
``
42
`+
import javax.swing.UIManager;
`
``
43
+
``
44
`+
public class JComboBoxActionEvent {
`
``
45
`+
private static final String instructionsText = " Click the arrow to display the menu.\n" +
`
``
46
`+
"While the menu is displayed, edit the text to create a new value.\n" +
`
``
47
`+
"Type return.\n" +
`
``
48
`+
"If a dialog appears with "ActionCommand received"\n" +
`
``
49
`+
"press Pass, else Fail";
`
``
50
+
``
51
`+
private static JFrame frame;
`
``
52
+
``
53
`+
public static void createAndShowGUI() throws Exception {
`
``
54
`+
SwingUtilities.invokeAndWait(() -> {
`
``
55
+
``
56
`+
JComboBox comboBox = new JComboBox<>(new String[]
`
``
57
`+
{ "Apple", "Orange", "Pear" });
`
``
58
`+
comboBox.setEditable(true);
`
``
59
`+
comboBox.addActionListener(e -> {
`
``
60
`+
System.out.println("Action Listener called: " + e.getActionCommand());
`
``
61
`+
if (e.getActionCommand().contains("comboBoxEdited")) {
`
``
62
`+
JOptionPane.showMessageDialog(null, "ActionCommand received");
`
``
63
`+
}
`
``
64
`+
});
`
``
65
+
``
66
`+
FlowLayout layout = new FlowLayout();
`
``
67
`+
JPanel panel = new JPanel(layout);
`
``
68
`+
panel.add(comboBox);
`
``
69
`+
frame = new JFrame("Test Editable Combo Box");
`
``
70
`+
frame.getContentPane().add(panel);
`
``
71
`+
frame.setVisible(true);
`
``
72
`+
frame.pack();
`
``
73
`+
frame.setLocationRelativeTo(null);
`
``
74
+
``
75
`+
PassFailJFrame.addTestWindow(frame);
`
``
76
`+
PassFailJFrame.positionTestWindow(frame,
`
``
77
`+
PassFailJFrame.Position.HORIZONTAL);
`
``
78
`+
});
`
``
79
`+
}
`
``
80
+
``
81
`+
public static void main(String[] args) throws Exception {
`
``
82
+
``
83
`+
UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
`
``
84
+
``
85
`+
PassFailJFrame pfjFrame = new PassFailJFrame("JScrollPane "
`
``
86
`+
- "Test Instructions", instructionsText, 5);
`
``
87
+
``
88
`+
createAndShowGUI();
`
``
89
+
``
90
`+
pfjFrame.awaitAndCheck();
`
``
91
`+
}
`
``
92
`+
}
`