Path: blob/master/test/jdk/javax/swing/JMenu/6470128/bug6470128.java
41153 views
/*1* Copyright (c) 2011, 2018, 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 647012827* @summary Escape Key causes JMenu Selection to Disappear28* @author Alexander Potochkin29* @library /test/lib30* @build jdk.test.lib.Platform31* @run main bug647012832*/3334import javax.swing.*;35import java.awt.*;36import java.awt.event.KeyEvent;3738import jdk.test.lib.Platform;3940public class bug6470128 {41static JFrame frame;42static JMenu subMenu;4344public static void main(String[] args) throws Exception {45try {46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48frame = new JFrame();49frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5051JMenuBar bar = new JMenuBar();52JMenu menu = new JMenu("Menu");53menu.setMnemonic('m');54subMenu = new JMenu("SubMenu");55JMenuItem item = new JMenuItem("Item");5657frame.setJMenuBar(bar);58bar.add(menu);59menu.add(subMenu);60subMenu.add(item);6162frame.setSize(200, 200);63frame.setLocationRelativeTo(null);64frame.setVisible(true);65}66});67Robot robot = new Robot();68robot.setAutoDelay(10);69robot.waitForIdle();70if (Platform.isOSX()) {71robot.keyPress(KeyEvent.VK_CONTROL);72}73robot.keyPress(KeyEvent.VK_ALT);74robot.keyPress(KeyEvent.VK_M);75robot.keyRelease(KeyEvent.VK_M);76robot.keyRelease(KeyEvent.VK_ALT);77if (Platform.isOSX()) {78robot.keyRelease(KeyEvent.VK_CONTROL);79}80robot.keyPress(KeyEvent.VK_ENTER);81robot.keyRelease(KeyEvent.VK_ENTER);82robot.keyPress(KeyEvent.VK_ESCAPE);83robot.keyRelease(KeyEvent.VK_ESCAPE);84robot.waitForIdle();85if (!subMenu.isSelected()) {86throw new RuntimeException("Submenu is unexpectedly unselected");87}88} finally {89if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());90}91}92}939495