tags:

views:

72

answers:

2

In a re-implementation of an existing program, I would like to keep the message text that users are familiar with. One of the enhancements I'd like to add is a good keyboard-only interface including mnemonics. But using the intuitive mnemonic character with the existing text gives some ugly results. For example:

    useUpperCheckBox = new JCheckBox("Use UPPERCASE letters");
    useUpperCheckBox.setMnemonic(KeyEvent.VK_U);

underlines the "U" in "Use" rather than the "U" in "UPPERCASE". Since the user's eye is naturally drawn to "UPPERCASE" looking for a mnemonic, the default location of the decoration is a bit unintuitive.

Yes, I've read the docs and the tutorials that say that the first instance of the mnemonic character is underlined, but that isn't what I want. It comes up often enough that I can't believe I'm the only one frustrated by this. Surely someone smarter than me has figured out how to place the decoration somewhere different than the default location.

+8  A: 

Use the source, Luke. Looking at the source code of setMnemonic() led me quickly to AbstractButton.setDisplayedMnemonicIndex():

Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic.

Michael Borgwardt
Perfect! Thanks for the pointer.
clartaq
+1 for teaching how to find the answer rather just giving the answer.
Nemi
+1  A: 

I think what you are looking for is: setDisplayedMnemonicIndex(int index)

rsp