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

Mac system menu bar handles some accelerators incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u60
    • 8u20
    • javafx
    • Mac OS X Mavericks 10.9.5, Java 8u20

      On Mac, using setSystemMenuBar(true), some Cmd+... shortcuts do not bind correctly. If you set an accelerator of Cmd-D or Cmd-E (for example), they work fine. If you set an accelerator of Cmd-K you instead find it is bound to Cmd-+, and Cmd-M gets bound to Cmd--. These are shown as Cmd-+ in the menubar, and are triggered by Cmd-+, despite asking for the Cmd-K binding. If you don't use the system menubar, the shortcuts work correctly.

      Code to reproduce:

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.input.KeyCharacterCombination;
      import javafx.scene.input.KeyCombination;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class TestMenuShortcuts extends Application {

          @Override
          public void start(Stage stage) throws Exception
          {
              VBox vbox = new VBox();
              Scene scene = new Scene(vbox);
              
              MenuBar m = new MenuBar();
              Menu menu = new Menu("JavaFX");
              MenuItem item = new MenuItem("My item");
              // Binding "d" or "e" works. Binding "k" or "m" doesn't:
              item.setAccelerator(new KeyCharacterCombination("k", KeyCombination.SHORTCUT_DOWN));
              item.setOnAction(e -> System.out.println("Triggered!"));
              menu.getItems().add(item);
              m.getMenus().add(menu);
              m.setUseSystemMenuBar(true);
              
              vbox.getChildren().addAll(m, new Label("Dummy scene content"));
              
              stage.setScene(scene);
              stage.show();
          }

      }

            morris Morris Meyer (Inactive)
            nbrownjfx Neil Brown (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: