我需要帮助来停用JButton的助记符。实际上,我正在使用第三方API,他们将助记符设置为“ Alt C”。所以我想删除该助记符,并且不想为此compButton设置任何内容(即想删除助记符)。
// Alt + 'C' selects the comp.
compButton.setMnemonic(KeyEvent.VK_C);
最佳答案
如何使用compButton.setMnemonic(0);
编辑:
我看到了javax/swing/AbstractButton.java
:
/**
* Returns key bindings associated with this object
*
* @return the key bindings, if supported, of the object;
* otherwise, null
* @see AccessibleKeyBinding
* @since 1.4
*/
public AccessibleKeyBinding getAccessibleKeyBinding() {
int mnemonic = AbstractButton.this.getMnemonic();
if (mnemonic == 0) {
return null;
}
return new ButtonKeyBinding(mnemonic);
}
因此,
compButton.setMnemonic(0);
看起来比compButton.setMnemonic(-1);
更好。关于java - 停用JButton的助记符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22635591/