Path: blob/master/test/jdk/javax/swing/JMenu/4417601/bug4417601.java
41155 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*/2223/*24* @test25* @key headful26* @bug 441760127* @summary JMenus with no items paint a tiny menu.28* @author Alexander Potochkin29* @library /lib/client30* @build ExtendedRobot31* @run main bug441760132*/3334import javax.swing.*;35import java.awt.event.*;36import java.awt.*;3738public class bug4417601 {39static JMenu menu;40static volatile boolean flag;41static JFrame frame;4243public static void main(String[] args) throws Exception {4445ExtendedRobot robot = new ExtendedRobot();46robot.setAutoDelay(10);4748SwingUtilities.invokeLater(new Runnable() {49public void run() {50frame = new JFrame();51frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);52menu = new JMenu("Menu");53JMenuBar bar = new JMenuBar();54bar.add(menu);55frame.setJMenuBar(bar);5657frame.getLayeredPane().addContainerListener(new ContainerAdapter() {58public void componentAdded(ContainerEvent e) {59flag = true;60}61});6263frame.pack();64frame.setSize(200, 200);65frame.setLocationRelativeTo(null);66frame.setVisible(true);67}68});69robot.waitForIdle();70Point p = menu.getLocationOnScreen();71Dimension size = menu.getSize();72p.x += size.width / 2;73p.y += size.height / 2;74robot.mouseMove(p.x, p.y);75robot.mousePress(InputEvent.BUTTON1_MASK);76robot.mouseRelease(InputEvent.BUTTON1_MASK);77robot.waitForIdle();78if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());79if (flag) {80throw new RuntimeException("Empty popup was shown");81}82}83}848586