Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/6515446/bug6515446.java
38854 views
/*1* Copyright (c) 2007, 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/*23@test24@bug 651544625@summary JMenuItems in JPopupMenus not receiving ActionEvents - incompat with 1.526@author Alexander Potochkin27@library ../../../../lib/testlibrary28@build ExtendedRobot29@run main bug651544630*/3132import javax.swing.*;33import java.awt.event.*;34import java.awt.*;3536public class bug6515446 {37private static JPanel panel;38private static volatile boolean flag;3940public static void main(String[] args) throws Exception {41SwingUtilities.invokeLater(new Runnable() {42public void run() {43final JFrame frame = new JFrame();44frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4546final JPopupMenu popup = new JPopupMenu("Menu");47JMenuItem item = new JMenuItem("MenuItem");48item.addActionListener(new ActionListener() {49public void actionPerformed(ActionEvent e) {50flag = true;51}52});53popup.add(item);5455panel = new JPanel();56panel.addMouseListener(new MouseAdapter() {57public void mousePressed(MouseEvent e) {58popup.show(panel, e.getX(), e.getY());59}6061public void mouseReleased(MouseEvent e) {62popup.setVisible(false);63}64});65frame.add(panel);66frame.setSize(200, 200);67frame.setLocationRelativeTo(null);68frame.setVisible(true);69}70});7172ExtendedRobot robot = new ExtendedRobot();73robot.setAutoDelay(10);74robot.waitForIdle();7576Point l = panel.getLocationOnScreen();7778int x = l.x + panel.getWidth() / 2;79int y = l.y + panel.getHeight() / 2;80robot.mouseMove(x, y);81robot.mousePress(InputEvent.BUTTON1_MASK);82robot.glide(x, y, x + 10, y + 10);83robot.mouseRelease(InputEvent.BUTTON1_MASK);84robot.waitForIdle();8586if (!flag) {87throw new RuntimeException("ActionEvent wasn't fired");88}89}90}919293