Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenuItem/ShortcutNotDiplayed/ShortcutNotDisplayedTest.java
38853 views
/*1* Copyright (c) 2012, 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* @run main/manual ShortcutNotDisplayedTest29*/3031import java.awt.*;32import java.awt.event.*;33import javax.swing.*;3435public class ShortcutNotDisplayedTest {36static volatile boolean done = false;37static volatile boolean pass = false;38static final String PASS_COMMAND = "pass";3940public static void main(String[] args) throws Exception {41if (sun.awt.OSInfo.getOSType() != sun.awt.OSInfo.OSType.MACOSX) {42System.out.println("This test is for MacOS only. Automatically passed on other platforms.");43return;44}45System.setProperty("apple.laf.useScreenMenuBar", "true");46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48createAndShowGUI();49}50});5152do { try { Thread.sleep(300); } catch (Exception e) {} } while (!done) ;53if (!pass) {54throw new Exception("Shortcuts not displayed as expected in the screen menu bar.");55}56}5758private static void createAndShowGUI() {59JMenuItem newItem = new JMenuItem("Exit");60newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, java.awt.event.InputEvent.META_MASK));6162JMenu menu = new JMenu("Test Frame Window Menu");63menu.setMnemonic(KeyEvent.VK_M);64menu.add(newItem);6566JMenuBar bar = new JMenuBar();67bar.add(menu);68JTextArea text = new JTextArea(69" Please follow instructions:\n" +70" 1. You should see \"Test Frame Window Menu\" menu on the screen menu bar.\n" +71" 2. Open \"Test Frame Window Menu\" menu. \n" +72" Check that menu item \"Exit\" has a shortcut with image for Command Key and symbol \"E\". \n" +73" If you see the shortcut press \"Passed\". Otherwise press \"Failed\".\n"74);75text.setEditable(false);7677JScrollPane sp = new JScrollPane(text);78sp.setSize(300,200);7980JButton passBtn = new JButton("Pass");81passBtn.setActionCommand(PASS_COMMAND);82JButton failBtn = new JButton("Fail");83ActionListener listener = new ActionListener() {84public void actionPerformed(ActionEvent e) {85if (e.getActionCommand().equals(PASS_COMMAND)) {86pass = true;87}88done = true;89}90};9192JFrame testFrame = new JFrame("Test Frame Window");93testFrame.setLayout(new FlowLayout());94testFrame.setBounds(100, 100, 600, 180);95testFrame.setJMenuBar(bar);96testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);97passBtn.addActionListener(listener);98failBtn.addActionListener(listener);99testFrame.getContentPane().add(sp);100testFrame.getContentPane().add(passBtn);101testFrame.getContentPane().add(failBtn);102testFrame.setVisible(true);103}104}105106107