Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/6987844/bug6987844.java
38854 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* @bug 698784426* @summary Incorrect width of JComboBox drop down27* @author Alexander Potochkin28* @run main bug698784429*/3031import javax.swing.*;32import java.awt.*;33import java.awt.event.InputEvent;3435public class bug6987844 {36static JMenu menu1;37static JMenu menu2;3839public static void main(String... args) throws Exception {40Robot robot = new Robot();41robot.setAutoDelay(200);4243SwingUtilities.invokeAndWait(new Runnable() {44public void run() {45JFrame frame = new JFrame();46frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4748JMenuBar bar = new JMenuBar();49menu1 = new JMenu("Menu1");50menu1.add(new JMenuItem("item"));51bar.add(menu1);52menu2 = new JMenu("Menu2");53menu2.add(new JMenuItem("item"));54menu2.add(new JMenuItem("item"));55bar.add(menu2);5657frame.setJMenuBar(bar);58frame.pack();5960frame.setVisible(true);61}62});63robot.waitForIdle();64Point point1 = menu1.getLocationOnScreen();65Point point2 = menu2.getLocationOnScreen();6667robot.mouseMove(point1.x + 1, point1.y + 1);68robot.mousePress(InputEvent.BUTTON1_MASK);69robot.mouseRelease(InputEvent.BUTTON1_MASK);7071robot.mouseMove(point2.x + 1, point2.y + 1);72robot.mousePress(InputEvent.BUTTON1_MASK);73robot.mouseRelease(InputEvent.BUTTON1_MASK);74robot.mousePress(InputEvent.BUTTON1_MASK);75robot.mouseRelease(InputEvent.BUTTON1_MASK);7677robot.mouseMove(point1.x + 1, point1.y + 1);78robot.waitForIdle();7980SwingUtilities.invokeAndWait(new Runnable() {81public void run() {82Dimension popupSize1 = menu1.getPopupMenu().getSize();83Dimension popupSize2 = menu2.getPopupMenu().getSize();84if (popupSize1.equals(popupSize2)) {85throw new RuntimeException("First popup unexpedetly changed its size");86}87}88});89}90}919293