Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deactivate mnemonic for JButton

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);
like image 915
mgr Avatar asked Jun 19 '26 14:06

mgr


1 Answers

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

like image 172
aterai Avatar answered Jun 22 '26 04:06

aterai