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