I need help to deactivate the Mnemonic for JButton. Actually I am using 3rd party API, which they set mnemonic as "Alt C". So I want to remove this mnemonic and wants to set nothing (i.e wants to remove the mnemonic) for this compButton.
// Alt + 'C' selects the comp.
compButton.setMnemonic(KeyEvent.VK_C);
How about using the compButton.setMnemonic(0);
edit:
I saw 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);
}
Therefore, compButton.setMnemonic(0); looks even better than compButton.setMnemonic(-1);.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With