[英]Setting JMenuItem accelerator text, not just action
For my swing application a JMenuItem
has the accelerator set like this:对于我的摇摆应用程序,
JMenuItem
的加速器设置如下:
JMenuItem numFieldsMI = new JMenuItem("Set Number of Fields");
numFieldsMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
This, when the GUI is intitialized, makes the text next to the menu item read "Ctrl+Shift+3" but of course the intent is that the text be "Ctrl+#".当 GUI 初始化时,这会使菜单项旁边的文本变为“Ctrl+Shift+3”,但当然意图是文本为“Ctrl+#”。 How can I do this?
我怎样才能做到这一点?
Change 更改
numFieldsMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
to 至
numFieldsMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
ActionEvent.CTRL_MASK ***|*** ActionEvent.SHIFT_MASK));
sahlaysta 公共库可以在任何外观上将自定义加速器文本设置为 JMenuItem: https : //github.com/sahlaysta/common/blob/main/com/github/sahlaysta/common/swing/JMenuItemUtil.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.