11/*
2- * Copyright (c) 2013, 2017 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2021 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2424/**
2525 * @test
2626 * @key headful
27- * @bug 8007267
27+ * @bug 8007267 8233648
2828 * @summary [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
2929 * @requires (os.family == "mac")
30- 31- * @modules java.desktop/sun.awt
32- * java.desktop/com.apple.eawt
33- * @run main DefaultMenuBarTest
30+ * @modules java.desktop/com.apple.eawt
31+ * @run main/othervm DefaultMenuBarTest
3432 */
3533
36- import java .awt .*;
37- import java .awt .event .*;
38- import javax .swing .*;
34+ import java .awt .Robot ;
35+ import javax .swing .JMenu ;
36+ import javax .swing .JMenuBar ;
37+ import javax .swing .JMenuItem ;
38+ import javax .swing .KeyStroke ;
39+ import javax .swing .SwingUtilities ;
40+ import java .awt .event .InputEvent ;
41+ import java .awt .event .KeyEvent ;
3942import java .lang .reflect .Method ;
4043
4144
@@ -50,14 +53,11 @@ public static void main(String[] args) throws Exception {
5053 }
5154
5255 System .setProperty ("apple.laf.useScreenMenuBar" , "true" );
53- SwingUtilities .invokeAndWait (new Runnable () {
54- public void run () {
55- createAndShowGUI ();
56- }
57- });
56+ SwingUtilities .invokeAndWait (DefaultMenuBarTest ::createAndShowGUI );
5857
5958 Robot robot = new Robot ();
6059 robot .setAutoDelay (100 );
60+ robot .waitForIdle ();
6161
6262 robot .keyPress (KeyEvent .VK_META );
6363 robot .keyPress (ks .getKeyCode ());
@@ -76,13 +76,7 @@ private static void createAndShowGUI() {
7676 JMenuItem newItem = new JMenuItem ("Open" );
7777
7878 newItem .setAccelerator (ks );
79- newItem .addActionListener (
80- new ActionListener (){
81- public void actionPerformed (ActionEvent e ) {
82- listenerCallCounter ++;
83- }
84- }
85- );
79+ newItem .addActionListener (e -> listenerCallCounter ++);
8680 menu .add (newItem );
8781
8882 JMenuBar defaultMenu = new JMenuBar ();
@@ -104,7 +98,7 @@ public void actionPerformed(ActionEvent e) {
10498 }
10599 }
106100 } catch (Exception e ) {
107- e . printStackTrace ( );
101+ throw new RuntimeException ( e );
108102 }
109103 }
110104}
0 commit comments