Java 停用JButton的助记符

Java 停用JButton的助记符,java,swing,jbutton,mnemonics,Java,Swing,Jbutton,Mnemonics,我需要帮助停用JButton的助记符。实际上,我使用的是第三方API,他们将助记符设置为“Alt C”。因此,我想删除这个助记符,并且不想为这个按钮设置任何内容(即想删除助记符) // Alt + 'C' selects the comp. compButton.setMnemonic(KeyEvent.VK_C); 如何使用compButton.setMnemonic(0) 编辑: 我看到了javax/swing/AbstractButton.java: /** * Re

我需要帮助停用JButton的助记符。实际上,我使用的是第三方API,他们将助记符设置为“Alt C”。因此,我想删除这个助记符,并且不想为这个按钮设置任何内容(即想删除助记符)

    // 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)更好

0实际上是为KeyEvent定义的。如果您想采用这种方法,我建议使用负值。