File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shortcut key for label

 
Swela Jathar
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pressing Alt+E will now select the textField field.
 
Swela Jathar
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Camick
Ranch Hand
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic