Path: blob/master/test/jdk/javax/swing/JMenuBar/4750590/bug4750590.java
41153 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/*24* @test25* @key headful26* @library ../../regtesthelpers27* @build Util28* @bug 4750590 801559729* @summary SwingSet: Cannot change Themes using menu accelerators30* @author Alexander Zuev31* @run main bug475059032*/3334import javax.swing.*;35import java.awt.event.*;36import java.awt.*;3738public class bug4750590 {3940public static PassedListener pass = new PassedListener();41public static volatile boolean passed = false;42private static JFrame mainFrame;4344public static void main(String args[]) throws Throwable {45try {46SwingUtilities.invokeAndWait(new Runnable() {47@Override48public void run() {49createAndShowGUI();50}51});5253Robot robo = new Robot();54robo.setAutoDelay(500);55robo.waitForIdle();5657Util.hitMnemonics(robo, KeyEvent.VK_F);58robo.keyPress(KeyEvent.VK_M);59robo.keyRelease(KeyEvent.VK_M);6061robo.waitForIdle();6263if (passed) {64System.out.println("Test passed!");65} else {66throw new RuntimeException("Test FAILED!");67}68} finally {69if (mainFrame != null) SwingUtilities.invokeAndWait(() -> mainFrame.dispose());70}71}7273private static void createAndShowGUI() {74mainFrame = new JFrame("Bug 4750590");75JMenuBar mbar = new JMenuBar();76JMenu menu = new JMenu("File");77menu.setMnemonic('F');78JMenu submenu = new JMenu("Submenu");79submenu.add(new JMenuItem("SubMenu Item 1")).setMnemonic('S');80submenu.add(new JMenuItem("SubMenu Item 2"));81menu.add(submenu);8283menu.add(new JMenuItem("Menu Item 1"));84JMenuItem menuItem = menu.add(new JMenuItem("Menu Item 2"));85menuItem.setMnemonic('M');86menuItem.addActionListener(pass);87mbar.add(menu);88mainFrame.setJMenuBar(mbar);8990mainFrame.setSize(200, 200);91mainFrame.setLocation(200, 200);92mainFrame.setVisible(true);93mainFrame.toFront();94}9596public static class PassedListener implements ActionListener {97public void actionPerformed(ActionEvent ev) {98passed = true;99}100}101102}103104105