Path: blob/master/test/jdk/javax/swing/JComboBox/6406264/bug6406264.java
41153 views
/*1* Copyright (c) 2006, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* @test27* @key headful28* @bug 640626429* @summary Tests that JComboBox's focusable popup can be shown.30* @author Mikhail Lapshin31* @run main bug640626432*/3334import javax.swing.JComboBox;35import javax.swing.JFrame;36import javax.swing.SwingUtilities;37import javax.swing.plaf.basic.BasicComboBoxUI;38import javax.swing.plaf.basic.ComboPopup;39import javax.swing.plaf.basic.BasicComboPopup;40import java.awt.*;4142public class bug6406264 extends JComboBox {4344static JFrame frame;45static bug6406264 comboBox;4647public static void main(String[] args) throws Exception {4849Robot robot = new Robot();50// Setup and show frame51SwingUtilities.invokeAndWait(52new Runnable() {53public void run() {54frame = new JFrame("JComboBox6406264 test");55frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5657comboBox = new bug6406264("One", "Two", "Three");58frame.getContentPane().add(comboBox);5960frame.setLocationRelativeTo(null);61frame.pack();62frame.setVisible(true);63}64}65);6667robot.waitForIdle();6869// Show popup70SwingUtilities.invokeAndWait(71new Runnable() {72public void run() {73comboBox.showPopup();74}75});76robot.waitForIdle();7778// Check that popup is visible79SwingUtilities.invokeAndWait(80new Runnable() {81public void run() {82if (comboBox.getUI().isPopupVisible(comboBox) == false)83{84throw new RuntimeException("A focusable popup is not visible " +85"in JComboBox!");86}87}88}89);9091frame.dispose();92}9394public bug6406264(Object ... items) {95super(items);96}9798public void updateUI() {99setUI(new CustomComboBoxUI());100}101102// Use FocusablePopup for our JComboBox103private class CustomComboBoxUI extends BasicComboBoxUI {104protected ComboPopup createPopup() {105return new FocusablePopup(bug6406264.this);106}107}108109// Popup window which can take a focus110private class FocusablePopup extends BasicComboPopup {111public FocusablePopup(JComboBox combo) {112super(combo);113}114115public boolean isFocusable() {116return true;117}118}119}120121122