Path: blob/master/test/jdk/javax/swing/JPopupMenu/6987844/bug6987844.java
41153 views
/*1* Copyright (c) 2010, 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 698784427* @summary Incorrect width of JComboBox drop down28* @author Alexander Potochkin29* @run main bug698784430*/3132import javax.swing.*;33import java.awt.*;34import java.awt.event.InputEvent;3536public class bug6987844 {37static JMenu menu1;38static JMenu menu2;39static JFrame frame;4041public static void main(String... args) throws Exception {42try {43Robot robot = new Robot();44robot.setAutoDelay(200);4546SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48frame = new JFrame();49frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5051JMenuBar bar = new JMenuBar();52menu1 = new JMenu("Menu1");53menu1.add(new JMenuItem("item"));54bar.add(menu1);55menu2 = new JMenu("Menu2");56menu2.add(new JMenuItem("item"));57menu2.add(new JMenuItem("item"));58bar.add(menu2);5960frame.setJMenuBar(bar);61frame.pack();6263frame.setVisible(true);64}65});66robot.waitForIdle();67Point point1 = menu1.getLocationOnScreen();68Point point2 = menu2.getLocationOnScreen();6970robot.mouseMove(point1.x + 1, point1.y + 1);71robot.mousePress(InputEvent.BUTTON1_MASK);72robot.mouseRelease(InputEvent.BUTTON1_MASK);7374robot.mouseMove(point2.x + 1, point2.y + 1);75robot.mousePress(InputEvent.BUTTON1_MASK);76robot.mouseRelease(InputEvent.BUTTON1_MASK);77robot.mousePress(InputEvent.BUTTON1_MASK);78robot.mouseRelease(InputEvent.BUTTON1_MASK);7980robot.mouseMove(point1.x + 1, point1.y + 1);81robot.waitForIdle();8283SwingUtilities.invokeAndWait(new Runnable() {84public void run() {85Dimension popupSize1 = menu1.getPopupMenu().getSize();86Dimension popupSize2 = menu2.getPopupMenu().getSize();87if (popupSize1.equals(popupSize2)) {88throw new RuntimeException("First popup unexpedetly changed its size");89}90}91});92} finally {93if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());94}95}96}979899