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

[macosx] ActionEvent is not fired for menu item with option apple.laf.useScreenMenuBar

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b120
    • Resolved In Build:
      b124

      Description

      Run the code below. Press "Menu->Menu Item" in the Apple menu bar. The action listener is not called and the "Menu is pressed!" string is not pressed.
      -----------
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.SwingUtilities;

      public class ClickMenuTest {

          public static void main(String[] args) {

              System.setProperty("apple.laf.useScreenMenuBar", "true");

              SwingUtilities.invokeLater(ClickMenuTest::createAndShowGUI);
          }

          private static void createAndShowGUI(){
              JFrame frame = new JFrame();
              frame.setSize(300, 300);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              JMenuBar menuBar = new JMenuBar();

              JMenu menu = new JMenu("Menu");
              JMenuItem menuItem = new JMenuItem("Menu Item");
              menuItem.addActionListener((e) ->{
                  System.out.println("Menu is pressed!");
              });

              menu.add(menuItem);
              menuBar.add(menu);
              frame.setJMenuBar(menuBar);
              frame.setVisible(true);
          }
      }
      -----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aniyogi Avik Niyogi (Inactive)
              Reporter:
              alexsch Alexandr Scherbatiy
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: