Another way to set mnemonic for JMenuItem?

最后都变了- 提交于 2019-12-02 08:57:29

The method setMnemonic(char mnemonic) is obsolete, you should use setMnemonic(int mnemonic) with the appropriate VK_E instead.

In any case the default behaviour is to underline first occurrence of the letter, if present. If you want to customize this thing you should look at AbstractButton class, it has a method (doc here:

public void setDisplayedMnemonicIndex(int index)

that does exactly what you need. So:

openProjectMenuItem.setMnemonic(VK_E);
openProjectMenuItem.setDisplayedMnemonicIndex(9);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!