26
26
* @key headful
27
27
* @bug 4983388 8015600
28
28
* @summary shortcuts on menus do not work on JDS
29
- * @author Oleg Mokhovikov
30
29
* @library ../../../../regtesthelpers
31
30
* @build Util
32
31
* @run main bug4983388
33
32
*/
34
33
35
- import java .awt .*;
36
- import javax .swing .*;
37
- import javax .swing .event .MenuListener ;
38
- import javax .swing .event .MenuEvent ;
34
+ import java .awt .Robot ;
39
35
import java .awt .event .KeyEvent ;
36
+ import java .util .concurrent .CountDownLatch ;
37
+
38
+ import javax .swing .JFrame ;
39
+ import javax .swing .JMenu ;
40
+ import javax .swing .JMenuBar ;
41
+ import javax .swing .SwingUtilities ;
42
+ import javax .swing .UIManager ;
43
+ import javax .swing .UnsupportedLookAndFeelException ;
44
+ import javax .swing .event .MenuEvent ;
45
+ import javax .swing .event .MenuListener ;
46
+
47
+ import static java .util .concurrent .TimeUnit .SECONDS ;
40
48
41
49
public class bug4983388 {
42
- static volatile boolean bMenuSelected = false ;
43
50
static JFrame frame ;
44
51
52
+ private static final CountDownLatch menuSelected = new CountDownLatch (1 );
53
+
45
54
private static class TestMenuListener implements MenuListener {
55
+ @ Override
46
56
public void menuCanceled (MenuEvent e ) {}
57
+ @ Override
47
58
public void menuDeselected (MenuEvent e ) {}
59
+
60
+ @ Override
48
61
public void menuSelected (MenuEvent e ) {
49
62
System .out .println ("menuSelected" );
50
- bMenuSelected = true ;
63
+ menuSelected . countDown () ;
51
64
}
52
65
}
53
66
@@ -56,42 +69,38 @@ private static void createAndShowGUI() {
56
69
JMenu menu = new JMenu ("File" );
57
70
menu .setMnemonic ('F' );
58
71
menuBar .add (menu );
59
- frame = new JFrame ();
72
+ menu .addMenuListener (new TestMenuListener ());
73
+
74
+ frame = new JFrame ("bug4983388" );
60
75
frame .setJMenuBar (menuBar );
61
76
frame .setLocationRelativeTo (null );
62
- frame .pack ( );
77
+ frame .setSize ( 250 , 100 );
63
78
frame .setVisible (true );
64
- MenuListener listener = new TestMenuListener ();
65
- menu .addMenuListener (listener );
66
79
}
67
80
68
81
public static void main (String [] args ) throws Exception {
69
-
70
82
try {
71
83
UIManager .setLookAndFeel ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
72
84
} catch (UnsupportedLookAndFeelException | ClassNotFoundException ex ) {
73
- System .err .println ("GTKLookAndFeel is not supported on this platform. Using defailt LaF for this platform." );
85
+ System .err .println ("GTKLookAndFeel is not supported on this platform. "
86
+ + "Using default LaF for this platform." );
74
87
}
75
88
76
- SwingUtilities .invokeAndWait (new Runnable () {
77
- public void run () {
78
- createAndShowGUI ();
79
- }
80
- });
89
+ SwingUtilities .invokeAndWait (bug4983388 ::createAndShowGUI );
81
90
82
91
Robot robot = new Robot ();
83
92
robot .setAutoDelay (50 );
84
93
robot .waitForIdle ();
85
94
robot .delay (500 );
86
95
87
96
Util .hitMnemonics (robot , KeyEvent .VK_F );
88
- robot .waitForIdle ();
89
- robot .delay (500 );
90
-
91
- SwingUtilities .invokeAndWait (() -> frame .dispose ());
92
97
93
- if (!bMenuSelected ) {
94
- throw new RuntimeException ("shortcuts on menus do not work" );
98
+ try {
99
+ if (!menuSelected .await (1 , SECONDS )) {
100
+ throw new RuntimeException ("shortcuts on menus do not work" );
101
+ }
102
+ } finally {
103
+ SwingUtilities .invokeAndWait (frame ::dispose );
95
104
}
96
105
}
97
106
}
0 commit comments