4

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?

Vikram
  • 3,996
  • 8
  • 37
  • 58

3 Answers3

5
button.setDisplayedMnemonicIndex(...);
camickr
  • 321,443
  • 19
  • 166
  • 288
5

Try this -

bt.setMnemonic('T');

bt.setDisplayedMnemonicIndex(6);

Hope that helps :)

sgibly
  • 3,828
  • 1
  • 21
  • 21
  • 1
    But, even here, we have to write both (bt.setMnemonic('T'); bt.setDisplayedMnemonicIndex(6);) Writing just one of those 2 statements doesn't help. – Vikram Jul 12 '11 at 15:52
0
JButton button = new JButton("Alter Today");
button.setMnemonic('T');
// or button.setMnemonic(6);
// or button.setMnemonic(KeyEvent.VK_T);
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417