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 /* 25 * @test 26 * @key headful 27 * @bug 4983388 8015600 28 * @summary shortcuts on menus do not work on JDS 29 * @author Oleg Mokhovikov 30 * @library ../../../../regtesthelpers 31 * @build Util 32 * @run main bug4983388 33 */ 34 35 import sun.awt.*; 36 import java.awt.*; 37 import javax.swing.*; 38 import javax.swing.event.MenuListener; 39 import javax.swing.event.MenuEvent; 40 import java.awt.event.KeyEvent; 41 42 public class bug4983388 { 43 static volatile boolean bMenuSelected = false; 44 45 private static class TestMenuListener implements MenuListener { 46 public void menuCanceled(MenuEvent e) {} 47 public void menuDeselected(MenuEvent e) {} 48 public void menuSelected(MenuEvent e) { 49 System.out.println("menuSelected"); 50 bMenuSelected = true; 51 } 52 } 53 54 private static void createAndShowGUI() { 55 JMenuBar menuBar = new JMenuBar(); 56 JMenu menu = new JMenu("File"); 57 menu.setMnemonic('F'); 58 menuBar.add(menu); 59 JFrame frame = new JFrame(); 60 frame.setJMenuBar(menuBar); 61 frame.pack(); 62 frame.setVisible(true); 63 MenuListener listener = new TestMenuListener(); 64 menu.addMenuListener(listener); 65 } 66 67 public static void main(String[] args) throws Exception { 68 69 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 70 try { 71 UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); 72 } catch (UnsupportedLookAndFeelException | ClassNotFoundException ex) { 73 System.err.println("GTKLookAndFeel is not supported on this platform. Using defailt LaF for this platform."); 74 } 75 76 SwingUtilities.invokeAndWait(new Runnable() { 77 public void run() { 78 createAndShowGUI(); 79 } 80 }); 81 82 Robot robot = new Robot(); 83 Util.hitMnemonics(robot, KeyEvent.VK_F); 84 85 toolkit.realSync(); 86 87 if (!bMenuSelected) { 88 throw new RuntimeException("shortcuts on menus do not work"); 89 } 90 } 91 }