Path: blob/master/test/jdk/javax/swing/JComboBox/ShowPopupAfterHidePopupTest/ShowPopupAfterHidePopupTest.java
41153 views
/*1* Copyright (c) 2013, 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*/2223/*24* @test25* @key headful26* @bug 800641727* @summary JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X28* @author Anton Litvinov29* @run main ShowPopupAfterHidePopupTest30*/3132import java.awt.*;3334import javax.swing.*;35import javax.swing.plaf.metal.*;3637public class ShowPopupAfterHidePopupTest {38private static JFrame frame = null;39private static JComboBox comboBox = null;40private static boolean popupIsVisible = false;4142public static void main(String[] args) throws Exception {43UIManager.setLookAndFeel(new MetalLookAndFeel());44Robot robot = new Robot();45SwingUtilities.invokeAndWait(new Runnable() {46@Override47public void run() {48frame = new JFrame("Popup Menu of JComboBox");49comboBox = new JComboBox(new String[]{"Item1", "Item2", "Item3"});50frame.getContentPane().add(comboBox);51frame.pack();52frame.setVisible(true);53}54});55robot.waitForIdle();5657SwingUtilities.invokeAndWait(new Runnable() {58@Override59public void run() {60comboBox.showPopup();61comboBox.hidePopup();62comboBox.showPopup();63}64});65robot.waitForIdle();6667SwingUtilities.invokeAndWait(new Runnable() {68@Override69public void run() {70popupIsVisible = comboBox.isPopupVisible();71frame.dispose();72}73});74if (!popupIsVisible) {75throw new RuntimeException("Calling hidePopup() affected the next call to showPopup().");76}77}78}798081