Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java
38854 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.EventQueue;24import java.awt.Robot;25import java.awt.Toolkit;26import java.awt.event.ActionEvent;27import java.awt.event.ActionListener;28import java.awt.event.KeyEvent;29import javax.swing.JComboBox;30import javax.swing.JFrame;31import javax.swing.WindowConstants;3233/**34* @test35* @bug 805789336* @author Alexander Scherbatiy37* @summary JComboBox actionListener never receives "comboBoxEdited"38* from getActionCommand39* @run main bug805789340*/41public class bug8057893 {4243private static volatile boolean isComboBoxEdited = false;4445public static void main(String[] args) throws Exception {46Robot robot = new Robot();47robot.setAutoDelay(50);4849EventQueue.invokeAndWait(() -> {50JFrame frame = new JFrame();51frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);52JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});53comboBox.setEditable(true);54comboBox.addActionListener(new ActionListener() {5556@Override57public void actionPerformed(ActionEvent e) {58if ("comboBoxEdited".equals(e.getActionCommand())) {59isComboBoxEdited = true;60}61}62});63frame.add(comboBox);64frame.pack();65frame.setVisible(true);66comboBox.requestFocusInWindow();67});6869robot.waitForIdle();7071robot.keyPress(KeyEvent.VK_A);72robot.keyRelease(KeyEvent.VK_A);73robot.keyPress(KeyEvent.VK_ENTER);74robot.keyRelease(KeyEvent.VK_ENTER);75robot.waitForIdle();7677if(!isComboBoxEdited){78throw new RuntimeException("ComboBoxEdited event is not fired!");79}80}81}828384