Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java
38854 views
1
/*
2
* Copyright (c) 2014, 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.EventQueue;
25
import java.awt.Robot;
26
import java.awt.Toolkit;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.event.KeyEvent;
30
import javax.swing.JComboBox;
31
import javax.swing.JFrame;
32
import javax.swing.WindowConstants;
33
34
/**
35
* @test
36
* @bug 8057893
37
* @author Alexander Scherbatiy
38
* @summary JComboBox actionListener never receives "comboBoxEdited"
39
* from getActionCommand
40
* @run main bug8057893
41
*/
42
public class bug8057893 {
43
44
private static volatile boolean isComboBoxEdited = false;
45
46
public static void main(String[] args) throws Exception {
47
Robot robot = new Robot();
48
robot.setAutoDelay(50);
49
50
EventQueue.invokeAndWait(() -> {
51
JFrame frame = new JFrame();
52
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
53
JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});
54
comboBox.setEditable(true);
55
comboBox.addActionListener(new ActionListener() {
56
57
@Override
58
public void actionPerformed(ActionEvent e) {
59
if ("comboBoxEdited".equals(e.getActionCommand())) {
60
isComboBoxEdited = true;
61
}
62
}
63
});
64
frame.add(comboBox);
65
frame.pack();
66
frame.setVisible(true);
67
comboBox.requestFocusInWindow();
68
});
69
70
robot.waitForIdle();
71
72
robot.keyPress(KeyEvent.VK_A);
73
robot.keyRelease(KeyEvent.VK_A);
74
robot.keyPress(KeyEvent.VK_ENTER);
75
robot.keyRelease(KeyEvent.VK_ENTER);
76
robot.waitForIdle();
77
78
if(!isComboBoxEdited){
79
throw new RuntimeException("ComboBoxEdited event is not fired!");
80
}
81
}
82
}
83
84