Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenu/6470128/bug6470128.java
38854 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*/22/* @test23@bug 647012824@summary Escape Key causes JMenu Selection to Disappear25@author Alexander Potochkin26@library ../../../../lib/testlibrary27@build jdk.testlibrary.OSInfo28@run main bug647012829*/30import javax.swing.*;31import java.awt.*;32import java.awt.event.KeyEvent;33import jdk.testlibrary.OSInfo;3435public class bug6470128 {36static JFrame frame;37static JMenu subMenu;3839public static void main(String[] args) throws Exception {40SwingUtilities.invokeAndWait(new Runnable() {41public void run() {42frame = new JFrame();43frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4445JMenuBar bar = new JMenuBar();46JMenu menu = new JMenu("Menu");47menu.setMnemonic('m');48subMenu = new JMenu("SubMenu");49JMenuItem item = new JMenuItem("Item");5051frame.setJMenuBar(bar);52bar.add(menu);53menu.add(subMenu);54subMenu.add(item);5556frame.setSize(200, 200);57frame.setLocationRelativeTo(null);58frame.setVisible(true);59}60});61Robot robot = new Robot();62robot.setAutoDelay(10);63robot.waitForIdle();64if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {65robot.keyPress(KeyEvent.VK_CONTROL);66}67robot.keyPress(KeyEvent.VK_ALT);68robot.keyPress(KeyEvent.VK_M);69robot.keyRelease(KeyEvent.VK_M);70robot.keyRelease(KeyEvent.VK_ALT);71if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {72robot.keyRelease(KeyEvent.VK_CONTROL);73}74robot.keyPress(KeyEvent.VK_ENTER);75robot.keyRelease(KeyEvent.VK_ENTER);76robot.keyPress(KeyEvent.VK_ESCAPE);77robot.keyRelease(KeyEvent.VK_ESCAPE);78robot.waitForIdle();79if (!subMenu.isSelected()) {80throw new RuntimeException("Submenu is unexpectedly unselected");81}82}83}848586