Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160645

[macosx] selecting a menu of screen menu bar item does not fire actionPerformed

XMLWordPrintable

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 9-ea+122)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X, 10.11.5 build: 15F34

      A DESCRIPTION OF THE PROBLEM :
      On macOS (Mac OS X) selecting a menu item with mouse, does not fire actionPerformed when menubar is a screen menu bar (Dapple.laf.useScreenMenuBar=true)
          
      If a keystroke is assigned to the menu item, the action is fired when pressing the keystroke.
      Using latest JDK8 this works.

      REGRESSION. Last worked in version 8u92

      ADDITIONAL REGRESSION INFORMATION:
      it worked in JDK 8 versions
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a menubar in a JFrame that is a screenmenubar on macOS (-Dapple.laf.useScreenMenuBar=true)
      Select an menu item with mouse.
      Or use attached example.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Action of menuitem is fired.
      ACTUAL -
      Action of menuitem is not fired

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no message

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Toolkit;
      import java.awt.event.ActionEvent;
      import java.awt.event.KeyEvent;

      import javax.swing.AbstractAction;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JOptionPane;
      import javax.swing.KeyStroke;

      /*
      Synopsis:
          On macOS (Mac OS X) selecting a menu of screen menu bar item does not fire actionPerformed
      Full OS version:
          Mac OS X, 10.11.5 build: 15F34
      Additional Configuration Information:
          
      Development Kit or Runtime version:
          Java(TM) SE Runtime Environment (build 9-ea+122)
          
      Description:
          On macOS (Mac OS X) selecting a menu item with mouse, does not fire actionPerformed when
          menubar is a screen menu bar (-Dapple.laf.useScreenMenuBar=true)
          
          If a keystroke is assigned to the menu item, the action is fired when pressing the keystroke.
          Using latest JDK8 this works.
          
      Steps to Reproduce:
          Create a menubar in a JFrame that is a screenmenubar on macOS (-Dapple.laf.useScreenMenuBar=true)
          Select an menu item with mouse.
          Or use attached example.
          
      Expected Results:
          Action of menuitem is fired.
          
      Actual Result:
          Action of menuitem is not fired
          
      Frequency: Allways
      Error Message: No message
      Workarround: none
      Severity: In screen menu bar menu items do not work!

       */
      public class ScreenMenuBar
      {
          
          
          private static void createAndShowGUI()
          {
              System.err.println("java.version: " + System.getProperty("java.runtime.version"));
              int shortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
              
              JFrame frame = new JFrame("ScreenMenuBar");
              frame.setSize(300, 300);
              
              // create a menubar with one menu and one menu item
              JMenuBar mb = new JMenuBar();
              JMenu menu = new JMenu("Test");
              mb.add(menu);
              JMenuItem mi = new JMenuItem(new AbstractAction("A Menu Item")
              {
                  @Override
                  public void actionPerformed(ActionEvent arg0)
                  {
                      // show a message when action is fired
                      JOptionPane.showMessageDialog(null, "Menu Item selected: \n" + arg0);
                  }
              });
              // assign a keystroke
              mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, shortcutKeyMask));
              menu.add(mi);
              frame.setJMenuBar(mb);
              
              frame.setVisible(true);
          }
          
          public static void main(String[] args)
          {
              // on macOS show menubar as ScreenMenuBar
              System.setProperty("apple.laf.useScreenMenuBar", "true");
              
              javax.swing.SwingUtilities.invokeLater(new Runnable()
              {
                  public void run()
                  {
                      createAndShowGUI();
                  }
              });
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround

            aniyogi Avik Niyogi (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: