• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

shortcut key for label

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have desktop application.I want to set shortcut key of character to Label.can I use setMnemonic() method on label???or any other solution.

Thank you in advance...
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JLabel itself doesn't handle mnemonics or shortcuts. You can specify that a label belongs to a component with the setLabelFor method. After that you can use setDisplayedMnemonic or setDisplayedMnemonicIndex to set the mnemonic for the label. This will however only request that the connected component (as specified in setLabelFor) will receive focus / be the currently selected component. It will not trigger anything.

I'm not sure if JLabel can handle key bindings. If so, you can perhaps use that.
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply........

You can specify that a label belongs to a component with the setLabelFor method. After that you can use setDisplayedMnemonic or setDisplayedMnemonicIndex to set the mnemonic for the label. This will however only request that the connected component (as specified in setLabelFor) will receive focus / be the currently selected component. It will not trigger anything.



but which component is convenient for this method???can you give me example??
 
Rob Spoor
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pressing Alt+E will now select the textField field.
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks rob....
but i want to call another form from label.Means i want to open form when i press key.
please help.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i want to open form when i press key



Then you should be using a JButton, not a label. You can add an ActionListener to the button and also set the mnemonic of the button.
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic