JavaFX:如何获取代表平台特定快捷键代码的字符?

JavaFX: How can I get the character the represents the platform specific SHORTCUT key code?

我正在编写一个 JavaFX 应用程序,我已经使用加速器将快捷键添加到应用程序菜单。

现在我正在创建应用程序帮助,我想描述一下快捷键的用法。

JavaFX 加速器的建议是使用 SHORTCUT 而不是 CONTROL (Windows) 和 COMMAND (Apple)。当 运行 不同平台上的应用程序显示正确的组合键时,这在菜单中工作正常。

例如MenuItem Exit我添加了显示为

的加速器SHORTCUT_DOWN + X

Ctrl+X下Windows

+X 下 Mac OS

现在我想得到解释(Ctrl+X, + X) 从系统中添加到用户帮助中。

是否可以向JavaFX询问菜单中加速器的呈现方式?或者获取菜单中使用的 SHORTCUT_DOWN 的显示?

提前致谢

索斯滕

根据文档,getDisplayText() method

Returns a string representation of this KeyCombination that is suitable for display in a user interface (for example, beside a menu item).

所以你只需要

String acceleratorAsString = menuItem.getAccelerator().getDisplayText();