1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 @bug 4983388 8015600 26 @summary shortcuts on menus do not work on JDS 27 @author Oleg Mokhovikov 28 @library ../../../../regtesthelpers 29 @build Util 30 @run main bug4983388 31 */ 32 33 import java.awt.*; 34 import javax.swing.*; 35 import javax.swing.event.MenuListener; 36 import javax.swing.event.MenuEvent; 37 import java.awt.event.KeyEvent; 38 39 public class bug4983388 { 40 static volatile boolean bMenuSelected = false; 41 42 private static class TestMenuListener implements MenuListener { 43 public void menuCanceled(MenuEvent e) {} 44 public void menuDeselected(MenuEvent e) {} 45 public void menuSelected(MenuEvent e) { 46 System.out.println("menuSelected"); 47 bMenuSelected = true; 48 } 49 } 50 51 private static void createAndShowGUI() { 52 JMenuBar menuBar = new JMenuBar(); 53 JMenu menu = new JMenu("File"); 54 menu.setMnemonic('F'); 55 menuBar.add(menu); 56 JFrame frame = new JFrame(); 57 frame.setJMenuBar(menuBar); 58 frame.pack(); 59 frame.setVisible(true); 60 MenuListener listener = new TestMenuListener(); 61 menu.addMenuListener(listener); 62 } 63 64 public static void main(String[] args) throws Exception { 65 66 try { 67 UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); 68 } catch (UnsupportedLookAndFeelException | ClassNotFoundException ex) { 69 System.err.println("GTKLookAndFeel is not supported on this platform. Using defailt LaF for this platform."); 70 } 71 72 SwingUtilities.invokeAndWait(new Runnable() { 73 public void run() { 74 createAndShowGUI(); 75 } 76 }); 77 78 Robot robot = new Robot(); 79 robot.waitForIdle(); 80 Util.hitMnemonics(robot, KeyEvent.VK_F); 81 robot.waitForIdle(); 82 robot.delay(1000); 83 84 if (!bMenuSelected) { 85 throw new RuntimeException("shortcuts on menus do not work"); 86 } 87 } 88 }