为JMenuItem设置助记符的另一种方法是什么? [英] Another way to set mnemonic for JMenuItem?

查看:133
本文介绍了为JMenuItem设置助记符的另一种方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个打开项目菜单项,我想为它设置助记符。我更喜欢它是Project word中的'e'字符。但是当我用

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

openProjectMenuItem.setMnemonic('e');

它将Open字中的'e'字符设置为助记符。有没有办法实现我想要的?

it sets 'e' character from Open word as mnemonic. Is there a way to achieve what I want?

推荐答案

方法 setMnemonic(char mnemonic)已过时,您应该使用 setMnemonic(int mnemonic)并使用相应的 VK_E

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

在任何情况下,默认行为都是为第一次出现的字母加下划线(如果存在)。如果你想自定义这个东西,你应该看看 AbstractButton 类,它有一个方法(doc 这里

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);

这篇关于为JMenuItem设置助记符的另一种方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆