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();
}
}
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();
}
}