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

[macos] Menu item actions do not work with Desktop.setDefaultMenuBar()

XMLWordPrintable

    • generic
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      macOS 14.4.1

      A DESCRIPTION OF THE PROBLEM :
      If this code is used, many menu item accelerators (e.g. Cmd-S) do not trigger the item's action:

                  if (app.isSupported(Desktop.Action.APP_MENU_BAR)) {
                      Desktop.getDesktop().setDefaultMenuBar(menuBar);
                  } else {
                      setJMenuBar(menuBar);
                  }

      If this is used instead, menu item accelerators do work:

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


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a project with this file
      2. Run it on macOS.
      3. Press Cmd-Delete. Nothing is printed to the console.
      4. Set `fixed = true` on line 11.
      5. Run.
      6. Press Cmd-Delete. "Delete pressed" is printed to the console.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The menu item's action should be triggered.
      ACTUAL -
      The menu item highlights, but the action is not triggered.

      ---------- BEGIN SOURCE ----------

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use:

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

      instead of:

      Desktop.getDesktop().setDefaultMenuBar(menuBar);

      FREQUENCY : always


            achung Alisen Chung
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: