Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenu/4417601/bug4417601.java
38853 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 441760124@summary JMenus with no items paint a tiny menu.25@author Alexander Potochkin26@library ../../../../lib/testlibrary27@build ExtendedRobot28@run main bug441760129*/3031import javax.swing.*;32import java.awt.event.*;33import java.awt.*;3435public class bug4417601 {36static JMenu menu;37static volatile boolean flag;3839public static void main(String[] args) throws Exception {4041ExtendedRobot robot = new ExtendedRobot();42robot.setAutoDelay(10);4344SwingUtilities.invokeLater(new Runnable() {45public void run() {46JFrame frame = new JFrame();47frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);48menu = new JMenu("Menu");49JMenuBar bar = new JMenuBar();50bar.add(menu);51frame.setJMenuBar(bar);5253frame.getLayeredPane().addContainerListener(new ContainerAdapter() {54public void componentAdded(ContainerEvent e) {55flag = true;56}57});5859frame.pack();60frame.setSize(200, 200);61frame.setLocationRelativeTo(null);62frame.setVisible(true);63}64});65robot.waitForIdle();66Point p = menu.getLocationOnScreen();67Dimension size = menu.getSize();68p.x += size.width / 2;69p.y += size.height / 2;70robot.mouseMove(p.x, p.y);71robot.mousePress(InputEvent.BUTTON1_MASK);72robot.mouseRelease(InputEvent.BUTTON1_MASK);73robot.waitForIdle();74if (flag) {75throw new RuntimeException("Empty popup was shown");76}77}78}798081