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 import sun.awt.SunToolkit; 34 35 /** 36 * @test 37 * @key headful 38 * @bug 8057893 39 * @author Alexander Scherbatiy 40 * @summary JComboBox actionListener never receives "comboBoxEdited" 41 * from getActionCommand 42 * @run main bug8057893 43 */ 44 public class bug8057893 { 45 46 private static volatile boolean isComboBoxEdited = false; 47 48 public static void main(String[] args) throws Exception { 49 Robot robot = new Robot(); 50 robot.setAutoDelay(50); 51 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 52 53 EventQueue.invokeAndWait(() -> { 54 JFrame frame = new JFrame(); 55 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 56 JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"}); 57 comboBox.setEditable(true); 58 comboBox.addActionListener(new ActionListener() { 59 60 @Override 61 public void actionPerformed(ActionEvent e) { 62 if ("comboBoxEdited".equals(e.getActionCommand())) { 63 isComboBoxEdited = true; 64 } 65 } 66 }); 67 frame.add(comboBox); 68 frame.pack(); 69 frame.setVisible(true); 70 comboBox.requestFocusInWindow(); 71 }); 72 73 toolkit.realSync(); 74 75 robot.keyPress(KeyEvent.VK_A); 76 robot.keyRelease(KeyEvent.VK_A); 77 robot.keyPress(KeyEvent.VK_ENTER); 78 robot.keyRelease(KeyEvent.VK_ENTER); 79 toolkit.realSync(); 80 81 if(!isComboBoxEdited){ 82 throw new RuntimeException("ComboBoxEdited event is not fired!"); 83 } 84 } 85 }