Path: blob/master/test/jdk/javax/swing/JPopupMenu/6515446/bug6515446.java
41155 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* @key headful25* @bug 651544626* @summary JMenuItems in JPopupMenus not receiving ActionEvents - incompat with 1.527* @author Alexander Potochkin28* @library /lib/client29* @build ExtendedRobot30* @run main bug651544631*/3233import javax.swing.*;34import java.awt.event.*;35import java.awt.*;3637public class bug6515446 {38private static JPanel panel;39private static volatile boolean flag;40private static JFrame frame;4142public static void main(String[] args) throws Exception {43try {44SwingUtilities.invokeLater(new Runnable() {45public void run() {46frame = new JFrame();47frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4849final JPopupMenu popup = new JPopupMenu("Menu");50JMenuItem item = new JMenuItem("MenuItem");51item.addActionListener(new ActionListener() {52public void actionPerformed(ActionEvent e) {53flag = true;54}55});56popup.add(item);5758panel = new JPanel();59panel.addMouseListener(new MouseAdapter() {60public void mousePressed(MouseEvent e) {61popup.show(panel, e.getX(), e.getY());62}6364public void mouseReleased(MouseEvent e) {65popup.setVisible(false);66}67});68frame.add(panel);69frame.setSize(200, 200);70frame.setLocationRelativeTo(null);71frame.setVisible(true);72}73});7475ExtendedRobot robot = new ExtendedRobot();76robot.setAutoDelay(10);77robot.waitForIdle();7879Point l = panel.getLocationOnScreen();8081int x = l.x + panel.getWidth() / 2;82int y = l.y + panel.getHeight() / 2;83robot.mouseMove(x, y);84robot.mousePress(InputEvent.BUTTON1_MASK);85robot.glide(x, y, x + 10, y + 10);86robot.mouseRelease(InputEvent.BUTTON1_MASK);87robot.waitForIdle();8889if (!flag) {90throw new RuntimeException("ActionEvent wasn't fired");91}92} finally {93if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());94}95}96}979899