• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Add mnemonic to text field

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been able to add mnemonics to buttons and they work.

Would someone here be able to tell me how to add a mnemonic for a text field?

The label for the text field allows for a mnemonic, but it has no function.
That is, when I press alt-m etc. there is no effect.

The properties tab for the JTextField does not mention mnemonic.

Advice on how to add these mnemonics would be appreciated.

TIA
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The label for the text field allows for a mnemonic, but it has no function.  That is, when I press alt-m etc. there is no effect.



This will just place focus on the text field.

What are you expecting to happen when you use a mnemonic?

Typically you add an ActionListener to a JTextField. The ActionListener would be invoked when the text field has focus and the Enter key is pressed.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:

The label for the text field allows for a mnemonic, but it has no function.  That is, when I press alt-m etc. there is no effect.



This will just place focus on the text field.

What are you expecting to happen when you use a mnemonic?

Typically you add an ActionListener to a JTextField. The ActionListener would be invoked when the text field has focus and the Enter key is pressed.



I simply would like to give focus to the text field when the mnemonic is pressed.

You mentioned above that this is what should take place, but it is not happening.
I noted that the text label had provision to state a mnemonic, but the JTextField
itself did not mention any mnemonic.

 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to also use:



so the label knows which component to focus on when the mnemonic is used.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:You need to also use:



so the label knows which component to focus on when the mnemonic is used.



Thanks Rob!
I couldn't find label.setLabelFor or where to put it, but I did find
labelFor under Properties for the JLabel.

I selected txtEmail from the list (the name of the JTextField)
and lo and behold, the mnemonic then worked!  

 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic