Path: blob/master/test/jdk/javax/swing/JMenuItem/ShortcutNotDiplayed/ShortcutNotDisplayedTest.java
41152 views
/*1* Copyright (c) 2012, 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* @bug 718637126* @summary [macosx] Main menu shortcuts not displayed27* @author [email protected]28* @library /test/lib29* @build jdk.test.lib.Platform30* @run main/manual ShortcutNotDisplayedTest31*/3233import jdk.test.lib.Platform;3435import java.awt.*;36import java.awt.event.*;37import javax.swing.*;3839public class ShortcutNotDisplayedTest {40static volatile boolean done = false;41static volatile boolean pass = false;42static final String PASS_COMMAND = "pass";4344public static void main(String[] args) throws Exception {45if (!Platform.isOSX()) {46System.out.println("This test is for MacOS only. Automatically passed on other platforms.");47return;48}49System.setProperty("apple.laf.useScreenMenuBar", "true");50SwingUtilities.invokeAndWait(new Runnable() {51public void run() {52createAndShowGUI();53}54});5556do { try { Thread.sleep(300); } catch (Exception e) {} } while (!done) ;57if (!pass) {58throw new Exception("Shortcuts not displayed as expected in the screen menu bar.");59}60}6162private static void createAndShowGUI() {63JMenuItem newItem = new JMenuItem("Exit");64newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, java.awt.event.InputEvent.META_MASK));6566JMenu menu = new JMenu("Test Frame Window Menu");67menu.setMnemonic(KeyEvent.VK_M);68menu.add(newItem);6970JMenuBar bar = new JMenuBar();71bar.add(menu);72JTextArea text = new JTextArea(73" Please follow instructions:\n" +74" 1. You should see \"Test Frame Window Menu\" menu on the screen menu bar.\n" +75" 2. Open \"Test Frame Window Menu\" menu. \n" +76" Check that menu item \"Exit\" has a shortcut with image for Command Key and symbol \"E\". \n" +77" If you see the shortcut press \"Passed\". Otherwise press \"Failed\".\n"78);79text.setEditable(false);8081JScrollPane sp = new JScrollPane(text);82sp.setSize(300,200);8384JButton passBtn = new JButton("Pass");85passBtn.setActionCommand(PASS_COMMAND);86JButton failBtn = new JButton("Fail");87ActionListener listener = new ActionListener() {88public void actionPerformed(ActionEvent e) {89if (e.getActionCommand().equals(PASS_COMMAND)) {90pass = true;91}92done = true;93}94};9596JFrame testFrame = new JFrame("Test Frame Window");97testFrame.setLayout(new FlowLayout());98testFrame.setBounds(100, 100, 600, 180);99testFrame.setJMenuBar(bar);100testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);101passBtn.addActionListener(listener);102failBtn.addActionListener(listener);103testFrame.getContentPane().add(sp);104testFrame.getContentPane().add(passBtn);105testFrame.getContentPane().add(failBtn);106testFrame.setVisible(true);107}108}109110111