Vikram
Vikram

Reputation: 4116

How to put mnemonic under the second instance of a Character (Java-Swing)?

I have a JButton named button1 with text "Alter Today".

I want to set a mnemonic under 'T' in the word 'Today' of this button (that is second instance of 't' or 'T' in 'Alter Today').

When I am trying to do:

button1.setMnemonic(6);

I am not able to see underlined 'T'.

When I am doing:

button1.setMnemonic('T');

it is still underlining 't' in the word 'Alter'.

How to do it?

Upvotes: 4

Views: 2123

Answers (3)

Eng.Fouad
Eng.Fouad

Reputation: 117665

JButton button = new JButton("Alter Today");
button.setMnemonic('T');
// or button.setMnemonic(6);
// or button.setMnemonic(KeyEvent.VK_T);

Upvotes: 0

sgibly
sgibly

Reputation: 3838

Try this -

bt.setMnemonic('T');

bt.setDisplayedMnemonicIndex(6);

Hope that helps :)

Upvotes: 5

camickr
camickr

Reputation: 324167

button.setDisplayedMnemonicIndex(...);

Upvotes: 5

Related Questions