Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenu/6359669/bug6359669.java
38854 views
/*1* Copyright (c) 2006, 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 635966924@summary REGRESSION: Submenu does not work if populated in PopupMenuListener.popupMenuWillBecomeVisible25@author Alexander Potochkin26@library ../../../../lib/testlibrary27@build ExtendedRobot28@run main bug635966929*/3031import javax.swing.*;32import javax.swing.event.PopupMenuListener;33import javax.swing.event.PopupMenuEvent;34import java.awt.*;35import java.awt.event.InputEvent;3637public class bug6359669 {38static JMenu menu;3940public static void main(String[] args) throws Exception {4142ExtendedRobot robot = new ExtendedRobot();43robot.setAutoDelay(10);4445SwingUtilities.invokeLater(new Runnable() {46public void run() {47JFrame f = new JFrame();48JMenuBar menuBar = new JMenuBar();49menu = new JMenu("Test");50menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {51public void popupMenuCanceled(PopupMenuEvent e) {52}5354public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {55}5657public void popupMenuWillBecomeVisible(PopupMenuEvent e) {58menu.add(new JMenuItem("An item"));59}60});6162menuBar.add(menu);63f.setJMenuBar(menuBar);6465f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);66f.setSize(200, 200);67f.setVisible(true);68}69});70robot.waitForIdle();71Point p = menu.getLocationOnScreen();72Dimension size = menu.getSize();73p.x += size.width / 2;74p.y += size.height / 2;75robot.mouseMove(p.x, p.y);76robot.mousePress(InputEvent.BUTTON1_MASK);77robot.mouseRelease(InputEvent.BUTTON1_MASK);78robot.waitForIdle();79if (menu.getPopupMenu().getComponentCount() == 0) {80throw new RuntimeException("Where is a menuItem ?");81}82}83}848586