Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComboBox/6559152/bug6559152.java
38854 views
/*1* Copyright (c) 2011, 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*/22/* @test23@bug 655915224@summary Checks that you can select an item in JComboBox with keyboard25when it is a JTable cell editor.26@author Mikhail Lapshin27@library ../../../../lib/testlibrary28@build ExtendedRobot29@run main bug655915230*/3132import javax.swing.*;33import javax.swing.table.DefaultTableModel;34import java.awt.*;35import java.awt.event.KeyEvent;3637public class bug6559152 {38private JFrame frame;39private JComboBox cb;40private ExtendedRobot robot;4142public static void main(String[] args) throws Exception {43final bug6559152 test = new bug6559152();44try {45SwingUtilities.invokeAndWait(new Runnable() {46public void run() {47test.setupUI();48}49});50test.test();51} finally {52if (test.frame != null) {53test.frame.dispose();54}55}56}5758private void setupUI() {59frame = new JFrame();60frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6162DefaultTableModel model = new DefaultTableModel(1, 1);63JTable table = new JTable(model);6465cb = new JComboBox(new String[]{"one", "two", "three"});66cb.setEditable(true);67table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb));68frame.add(cb);6970frame.pack();71frame.setLocationRelativeTo(null);72frame.setVisible(true);73}7475private void test() throws Exception {76robot = new ExtendedRobot();77robot.waitForIdle();78testImpl();79robot.waitForIdle();80checkResult();81}8283private void testImpl() throws Exception {84robot.type(KeyEvent.VK_DOWN);85robot.waitForIdle();86robot.type(KeyEvent.VK_DOWN);87robot.waitForIdle();88robot.type(KeyEvent.VK_ENTER);89}9091private void checkResult() {92if (cb.getSelectedItem().equals("two")) {93System.out.println("Test passed");94} else {95System.out.println("Test failed");96throw new RuntimeException("Cannot select an item " +97"from popup with the ENTER key.");98}99}100}101102103