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