所以,我有一个“打开项目”菜单项,我想为其设置助记符。我更喜欢它是 Project word 中的 'e' 字符。但是当我设置它时
openProjectMenuItem.setMnemonic('e');
它将 Open word 中的“e”字符设置为助记符。有没有办法实现我想要的?
该方法setMnemonic(char mnemonic)
已过时,您应该使用setMnemonic(int mnemonic)
适当的VK_E
代替。
在任何情况下,默认行为是在第一次出现的字母(如果存在)下加下划线。如果你想定制这个东西,你应该看看类,它有一个方法(这里AbstractButton
的文档:
public void setDisplayedMnemonicIndex(int index)
这正是你所需要的。所以:
openProjectMenuItem.setMnemonic(VK_E);
openProjectMenuItem.setDisplayedMnemonicIndex(9);