Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenuBar/4750590/bug4750590.java
38854 views
/*1* Copyright (c) 2013, 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/* @test24@library ../../regtesthelpers25@build Util26@bug 4750590 801559727@summary SwingSet: Cannot change Themes using menu accelerators28@author Alexander Zuev29@run main bug475059030*/3132import javax.swing.*;33import java.awt.event.*;34import java.awt.*;3536public class bug4750590 {3738public static PassedListener pass = new PassedListener();39public static volatile boolean passed = false;4041public static void main(String args[]) throws Throwable {4243SwingUtilities.invokeAndWait(new Runnable() {44@Override45public void run() {46createAndShowGUI();47}48});4950Robot robo = new Robot();51robo.setAutoDelay(500);52robo.waitForIdle();5354Util.hitMnemonics(robo, KeyEvent.VK_F);55robo.keyPress(KeyEvent.VK_M);56robo.keyRelease(KeyEvent.VK_M);5758robo.waitForIdle();5960if (passed) {61System.out.println("Test passed!");62} else {63throw new RuntimeException("Test FAILED!");64}65}6667private static void createAndShowGUI() {68JFrame mainFrame = new JFrame("Bug 4750590");69JMenuBar mbar = new JMenuBar();70JMenu menu = new JMenu("File");71menu.setMnemonic('F');72JMenu submenu = new JMenu("Submenu");73submenu.add(new JMenuItem("SubMenu Item 1")).setMnemonic('S');74submenu.add(new JMenuItem("SubMenu Item 2"));75menu.add(submenu);7677menu.add(new JMenuItem("Menu Item 1"));78JMenuItem menuItem = menu.add(new JMenuItem("Menu Item 2"));79menuItem.setMnemonic('M');80menuItem.addActionListener(pass);81mbar.add(menu);82mainFrame.setJMenuBar(mbar);8384mainFrame.setSize(200, 200);85mainFrame.setLocation(200, 200);86mainFrame.setVisible(true);87mainFrame.toFront();88}8990public static class PassedListener implements ActionListener {91public void actionPerformed(ActionEvent ev) {92passed = true;93}94}9596}979899