2

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

1 回答 1

3

如何使用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);.

于 2014-03-25T15:17:37.113 回答