JavaFX菜单项在右侧显示快捷方式 [英] JavaFX menu item show shortcuts on right hand side

查看:699
本文介绍了JavaFX菜单项在右侧显示快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以JavaFX Scene Builder中编辑菜单中的菜单项为例

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

看看他们如何显示右边的快捷方式?有没有简单的方法可以使用JavaFX实现相同的效果?谢谢。

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

推荐答案

您可以在场景构建器中添加加速键,或直接将其添加到fxml文件中,如此

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>

如果通过in javafx表示不使用fxml,则可以使用 mnuSave .setAccelerator(KeyCombination);

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

这篇关于JavaFX菜单项在右侧显示快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆