1 /* 2 * Copyright (c) 2013, 2015, 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 import java.awt.Robot; 25 import java.awt.Toolkit; 26 import java.awt.event.KeyEvent; 27 import javax.swing.JFileChooser; 28 import javax.swing.SwingUtilities; 29 import javax.swing.UIManager; 30 import javax.swing.UIManager.LookAndFeelInfo; 31 import sun.awt.SunToolkit; 32 33 /** 34 * @test 35 * @bug 8002077 36 * @author Alexander Scherbatiy 37 * @summary Possible mnemonic issue on JFileChooser Save button on nimbus L&F 38 * @library ../../regtesthelpers/ 39 * @build Util 40 * @run main bug8002077 41 */ 42 public class bug8002077 { 43 44 private static volatile int fileChooserState = JFileChooser.ERROR_OPTION; 45 46 public static void main(String[] args) throws Exception { 47 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 48 if ("Nimbus".equals(info.getName())) { 49 UIManager.setLookAndFeel(info.getClassName()); 50 UIManager.put("FileChooser.openButtonMnemonic", KeyEvent.VK_O); 51 UIManager.put("FileChooser.saveButtonMnemonic", KeyEvent.VK_S); 52 runTest(); 53 break; 54 } 55 } 56 } 57 58 private static void runTest() throws Exception { 59 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 60 Robot robot = new Robot(); 61 robot.setAutoDelay(50); 62 63 SwingUtilities.invokeLater(() -> 64 fileChooserState = new JFileChooser().showSaveDialog(null)); 65 toolkit.realSync(); 66 67 Util.hitMnemonics(robot, KeyEvent.VK_N); 68 toolkit.realSync(); 69 70 Util.hitKeys(robot, KeyEvent.VK_A); 71 toolkit.realSync(); 72 73 Util.hitMnemonics(robot, KeyEvent.VK_S); 74 toolkit.realSync(); 75 76 if (fileChooserState != JFileChooser.APPROVE_OPTION) { 77 // Close the dialog 78 Util.hitKeys(robot, KeyEvent.VK_ESCAPE); 79 toolkit.realSync(); 80 81 throw new RuntimeException("Save button is not pressed!"); 82 } 83 } 84 }