1 2 /* 3 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * @test 27 * @bug 4917669 28 * @summary 1.4 REGRESSION: MenuItem accelerator doesn't work if parent menu is in JDialog 29 * @author Alexander Zuev 30 * @library ../../regtesthelpers 31 * @run main bug4917669 32 */ 33 34 import javax.swing.*; 35 import java.awt.event.*; 36 import java.awt.*; 37 import sun.awt.SunToolkit; 38 39 public class bug4917669 { 40 41 private static volatile boolean passed = false; 42 private static JFrame mainFrame; 43 44 public static void main(String[] args) throws Exception { 45 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 46 Robot robot = new Robot(); 47 robot.setAutoDelay(500); 48 49 SwingUtilities.invokeAndWait(new Runnable() { 50 51 @Override 52 public void run() { 53 createAndShowGUI(); 54 } 55 }); 56 57 toolkit.realSync(); 58 59 SwingUtilities.invokeAndWait(new Runnable() { 60 61 @Override 62 public void run() { 63 createAndShowDialog(); 64 } 65 }); 66 67 toolkit.realSync(); 68 69 Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_O); 70 toolkit.realSync(); 71 72 if (!passed) { 73 throw new RuntimeException("Action did not received by menu item."); 74 } 75 } 76 77 private static void createAndShowDialog() { 78 JDialog dialog = new JDialog(mainFrame, "Test Dialog", false); 79 JMenuBar mb = new JMenuBar(); 80 JMenu file = new JMenu("File"); 81 JMenuItem menuItem = new JMenuItem("Open"); 82 menuItem.setAccelerator(KeyStroke.getKeyStroke("control O")); 83 menuItem.addActionListener(new ActionListener() { 84 85 public void actionPerformed(ActionEvent e) { 86 passed = true; 87 } 88 }); 89 file.add(menuItem); 90 mb.add(file); 91 dialog.setJMenuBar(mb); 92 93 dialog.setSize(100, 100); 94 dialog.setLocation(200, 200); 95 dialog.setVisible(true); 96 } 97 98 private static void createAndShowGUI() { 99 mainFrame = new JFrame("Bug4917669"); 100 mainFrame.setLayout(new BorderLayout()); 101 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 102 mainFrame.setSize(50, 50); 103 mainFrame.setVisible(true); 104 } 105 106 }