1 /* 2 * Copyright (c) 2011, 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 6596966 26 @summary Some JFileChooser mnemonics do not work with sticky keys 27 @library ../../regtesthelpers 28 @library ../../../../lib/testlibrary 29 @build Util jdk.testlibrary.OSInfo 30 @run main bug6596966 31 @author Pavel Porvatov 32 */ 33 34 import java.awt.*; 35 import java.awt.event.KeyEvent; 36 import java.awt.event.InputEvent; 37 import java.util.ArrayList; 38 import javax.swing.*; 39 40 import jdk.testlibrary.OSInfo; 41 42 public class bug6596966 { 43 private static JFrame frame; 44 45 private static JLabel label; 46 private static JButton button; 47 private static JComboBox comboBox; 48 49 public static void main(String[] args) throws Exception { 50 Robot robot = new Robot(); 51 52 SwingUtilities.invokeAndWait(new Runnable() { 53 public void run() { 54 button = new JButton("Button"); 55 comboBox = new JComboBox(); 56 57 label = new JLabel("Label"); 58 label.setDisplayedMnemonic('L'); 59 label.setLabelFor(comboBox); 60 61 JPanel pnContent = new JPanel(); 62 63 pnContent.add(button); 64 pnContent.add(label); 65 pnContent.add(comboBox); 66 67 frame = new JFrame(); 68 69 frame.add(pnContent); 70 frame.pack(); 71 frame.setVisible(true); 72 } 73 }); 74 75 robot.waitForIdle(); 76 77 78 int keyMask = InputEvent.ALT_MASK; 79 if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { 80 keyMask = InputEvent.CTRL_MASK | InputEvent.ALT_MASK; 81 } 82 ArrayList<Integer> keys = Util.getKeyCodesFromKeyMask(keyMask); 83 for (int i = 0; i < keys.size(); ++i) { 84 robot.keyPress(keys.get(i)); 85 } 86 87 robot.keyPress(KeyEvent.VK_L); 88 89 robot.waitForIdle(); 90 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED, 91 EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L')); 92 93 robot.waitForIdle(); 94 95 try { 96 SwingUtilities.invokeAndWait(new Runnable() { 97 public void run() { 98 if (!comboBox.isFocusOwner()) { 99 throw new RuntimeException("comboBox isn't focus owner"); 100 } 101 } 102 }); 103 } finally { 104 robot.keyRelease(KeyEvent.VK_L); 105 for (int i = 0; i < keys.size(); ++i) { 106 robot.keyRelease(keys.get(i)); 107 } 108 robot.waitForIdle(); 109 } 110 } 111 }