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 6921687 8079428
26 @summary Mnemonic disappears after repeated attempts to open menu items using
27 mnemonics
28 @author Semyon Sadetsky
29 @library /lib/testlibrary
30 @build jdk.testlibrary.OSInfo
31 @run main bug6921687
32 */
33
34
35 import jdk.testlibrary.OSInfo;
36 import javax.swing.*;
37 import java.awt.*;
38 import java.awt.event.KeyEvent;
39
40
41 public class bug6921687 {
42
43 private static Class lafClass;
44 private static JFrame frame;
45
46 public static void main(String[] args) throws Exception {
47 if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
48 System.out.println("Only Windows platform test. Test is skipped.");
49 System.out.println("ok");
50 return;
51 }
52 lafClass = Class.forName(UIManager.getSystemLookAndFeelClassName());
53 UIManager.setLookAndFeel((LookAndFeel) lafClass.newInstance());
54 try {
55 SwingUtilities.invokeAndWait(new Runnable() {
56 public void run() {
57 frame = new JFrame();
58 frame.setUndecorated(true);
59 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
60 setup(frame);
61 }
62 });
63
64 final Robot robot = new Robot();
65 robot.setAutoDelay(20);
66 robot.keyPress(KeyEvent.VK_ALT);
67 robot.keyPress(KeyEvent.VK_F);
68 robot.keyRelease(KeyEvent.VK_F);
69 robot.keyRelease(KeyEvent.VK_ALT);
70 robot.waitForIdle();
71 checkMnemonics();
72
73 robot.keyPress(KeyEvent.VK_ALT);
74 robot.keyPress(KeyEvent.VK_S);
75 robot.keyRelease(KeyEvent.VK_S);
76 robot.keyRelease(KeyEvent.VK_ALT);
77 robot.waitForIdle();
78 checkMnemonics();
79 System.out.println("ok");
80 } finally {
81 frame.dispose();
82 }
83
84 }
91
92 private static void setup(JFrame frame) {
93 JMenuBar menuBar = new JMenuBar();
94 frame.setJMenuBar(menuBar);
95
96 // First Menu, F - Mnemonic
97 JMenu firstMenu = new JMenu("First Menu");
98 firstMenu.setMnemonic(KeyEvent.VK_F);
99 firstMenu.add(new JMenuItem("One", KeyEvent.VK_O));
100 firstMenu.add(new JMenuItem("Two", KeyEvent.VK_T));
101 menuBar.add(firstMenu);
102
103 // Second Menu, S - Mnemonic
104 JMenu secondMenu = new JMenu("Second Menu");
105 secondMenu.setMnemonic(KeyEvent.VK_S);
106 secondMenu.add(new JMenuItem("A Menu Item", KeyEvent.VK_A));
107 menuBar.add(secondMenu);
108
109 frame.setSize(350, 250);
110 frame.setVisible(true);
111
112 }
113 }
|
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 * @bug 6921687 8079428
27 * @summary Mnemonic disappears after repeated attempts to open menu items using
28 * mnemonics
29 * @author Semyon Sadetsky
30 * @library /lib/testlibrary
31 * @build jdk.testlibrary.Platform
32 * @requires (os.family == "windows")
33 * @modules java.desktop/com.sun.java.swing.plaf.windows
34 * @run main bug6921687
35 */
36 import java.awt.Robot;
37 import java.awt.event.KeyEvent;
38 import javax.swing.JFrame;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuBar;
41 import javax.swing.JMenuItem;
42 import javax.swing.SwingUtilities;
43 import javax.swing.UIManager;
44 import jdk.testlibrary.Platform;
45
46 public class bug6921687 {
47
48 private static Class lafClass;
49 private static JFrame frame;
50
51 public static void main(String[] args) throws Exception {
52 if (!Platform.isWindows()) {
53 System.out.println("Only Windows platform test. Test is skipped.");
54 System.out.println("ok");
55 return;
56 }
57 final String lafClassName = UIManager.getSystemLookAndFeelClassName();
58 lafClass = Class.forName(lafClassName);
59 UIManager.setLookAndFeel(lafClassName);
60 try {
61 SwingUtilities.invokeAndWait(() -> {
62 frame = new JFrame();
63 frame.setUndecorated(true);
64 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65 setup(frame);
66 });
67
68 final Robot robot = new Robot();
69 robot.waitForIdle();
70 robot.setAutoDelay(20);
71 robot.keyPress(KeyEvent.VK_ALT);
72 robot.keyPress(KeyEvent.VK_F);
73 robot.keyRelease(KeyEvent.VK_F);
74 robot.keyRelease(KeyEvent.VK_ALT);
75 robot.waitForIdle();
76 checkMnemonics();
77
78 robot.keyPress(KeyEvent.VK_ALT);
79 robot.keyPress(KeyEvent.VK_S);
80 robot.keyRelease(KeyEvent.VK_S);
81 robot.keyRelease(KeyEvent.VK_ALT);
82 robot.waitForIdle();
83 checkMnemonics();
84 System.out.println("ok");
85 } finally {
86 frame.dispose();
87 }
88
89 }
96
97 private static void setup(JFrame frame) {
98 JMenuBar menuBar = new JMenuBar();
99 frame.setJMenuBar(menuBar);
100
101 // First Menu, F - Mnemonic
102 JMenu firstMenu = new JMenu("First Menu");
103 firstMenu.setMnemonic(KeyEvent.VK_F);
104 firstMenu.add(new JMenuItem("One", KeyEvent.VK_O));
105 firstMenu.add(new JMenuItem("Two", KeyEvent.VK_T));
106 menuBar.add(firstMenu);
107
108 // Second Menu, S - Mnemonic
109 JMenu secondMenu = new JMenu("Second Menu");
110 secondMenu.setMnemonic(KeyEvent.VK_S);
111 secondMenu.add(new JMenuItem("A Menu Item", KeyEvent.VK_A));
112 menuBar.add(secondMenu);
113
114 frame.setSize(350, 250);
115 frame.setVisible(true);
116 }
117 }
|