[英]Java - Add accelerator to a JMenuItem
I want to set an accelerator to a JMenuItem. 我想将加速器设置为JMenuItem。
Right now I am setting it like this 现在我要像这样设置
openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
and it's working but I don't want ctrl+o as accelerator. 它正在工作,但我不希望ctrl + o作为加速器。 I want 'space' as accelerator but I didn't find any method by which I can generate a KeyStroke corresponding to 'space'.
我希望将“ space”用作加速器,但没有找到任何方法可以生成与“ space”相对应的KeyStroke。
KeyStroke.getStroke()
either takes a char or (int, int). 要么接受一个char要么(int,int)。 I didn't find any char corresponding to space also.
我也找不到对应于空格的任何字符。
..didn't find any char corresponding to space also.
..也找不到与空间相对应的任何字符。
I would not be surprised if Swing ignores it, since ' '
is an unusual & hard to see accelerator. 如果Swing忽略它,我不会感到惊讶,因为
' '
是不常见且很难看到的加速器。
Most UI delegates render a KeyEvent.VK_SPACE
accelerator using something like the METRICAL TETRASEME
: ⏘ ( U+23D8
). 大多数UI委托使用
METRICAL TETRASEME
:⏘( U+23D8
)之类的东西来呈现KeyEvent.VK_SPACE
加速器。 For example, an Action
might include these lines: 例如,一个
Action
可能包括以下几行:
static final int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, MASK));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.