我需要帮助取消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);
更好。