JavaFX menu item show shortcuts on right hand side

怎甘沉沦 提交于 2019-12-08 17:09:25

问题


Take for example the menu items from the edit menu in JavaFX Scene Builder

See how they display the shortcuts on the right? Is there any easy way to achieve the same effect using JavaFX? Thanks.


回答1:


You can add an accelerator key in scene builder or add it directly in the fxml file like so

      <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>

If by "in javafx" you mean without using fxml you can use mnuSave.setAccelerator(KeyCombination);



来源:https://stackoverflow.com/questions/21209461/javafx-menu-item-show-shortcuts-on-right-hand-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!