Another way to set mnemonic for JMenuItem?

后端 未结 1 1552
暖寄归人
暖寄归人 2021-01-29 00:18

So, I have a \"Open Project\" menu item, and I want to set mnemonic to it. I prefer it to be \'e\' character from Project word. But when I set it with

openProjec         


        
相关标签:
1条回答
  • 2021-01-29 00:48

    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);
    
    0 讨论(0)
提交回复
热议问题