【问题标题】:deactivate mnemonic for JButton停用 JButton 的助记符
【发布时间】:2014-03-25 13:06:43
【问题描述】:

我需要帮助来停用 JButton 的助记符。实际上我使用的是第 3 方 API,他们将助记符设置为“Alt C”。所以我想删除这个助记符并且不想为这个compButton设置任何东西(即想删除助记符)。

    // Alt + 'C' selects the comp.
     compButton.setMnemonic(KeyEvent.VK_C);

【问题讨论】:

    标签: java swing jbutton mnemonics


    【解决方案1】:

    如何使用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 定义的。如果您想采用这种方法,我建议使用负值。
    猜你喜欢
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多