例如,以JavaFX Scene Builder中的编辑菜单中的菜单项为例
看看它们如何在右侧显示快捷方式?有没有简单的方法可以使用JavaFX达到相同的效果?谢谢。
<MenuItem mnemonicParsing="true" onAction="#mnuSaveAction" text="%menu.title.save" fx:id="mnuSave">
<accelerator>
<KeyCodeCombination alt="UP" code="S" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
如果使用“在javafx中,则表示不使用fxml,则可以使用mnuSave.setAccelerator(KeyCombination);
MenuItem gotoLine = new MenuItem("Goto");
KeyCombination gotoKeyCombination = new KeyCodeCombination(KeyCode.G, KeyCombination.CONTROL_DOWN);
gotoLine.setAccelerator(gotoKeyCombination);
gotoLine.setOnAction(event -> {
System.out.println("CTRL+G event triggered");
System.out.println(event.toString());
});