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 38 public class bug4917669 { 39 40 private static volatile boolean passed = false; 41 private static JFrame mainFrame; 42 43 public static void main(String[] args) throws Exception { 44 Robot robot = new Robot(); 45 robot.setAutoDelay(500); 46 47 SwingUtilities.invokeAndWait(new Runnable() { 48 49 @Override 50 public void run() { 51 createAndShowGUI(); 52 } 53 }); 54 55 robot.waitForIdle(); 56 57 SwingUtilities.invokeAndWait(new Runnable() { 58 59 @Override 60 public void run() { 61 createAndShowDialog(); 62 } 63 }); 64 65 robot.waitForIdle(); 66 67 Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_O); 68 robot.waitForIdle(); 69 70 if (!passed) { 71 throw new RuntimeException("Action did not received by menu item."); 72 } 73 } 74 75 private static void createAndShowDialog() { 76 JDialog dialog = new JDialog(mainFrame, "Test Dialog", false); 77 JMenuBar mb = new JMenuBar(); 78 JMenu file = new JMenu("File"); 79 JMenuItem menuItem = new JMenuItem("Open"); 80 menuItem.setAccelerator(KeyStroke.getKeyStroke("control O")); 81 menuItem.addActionListener(new ActionListener() { 82 83 public void actionPerformed(ActionEvent e) { 84 passed = true; 85 } 86 }); 87 file.add(menuItem); 88 mb.add(file); 89 dialog.setJMenuBar(mb); 90 91 dialog.setSize(100, 100); 92 dialog.setLocation(200, 200); 93 dialog.setVisible(true); 94 } 95 96 private static void createAndShowGUI() { 97 mainFrame = new JFrame("Bug4917669"); 98 mainFrame.setLayout(new BorderLayout()); 99 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 100 mainFrame.setSize(50, 50); 101 mainFrame.setVisible(true); 102 } 103 104 }