permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes shortcut key for label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "shortcut key for label" Watch "shortcut key for label" New topic
Author

shortcut key for label

Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19653
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19653
    
  18

Pressing Alt+E will now select the textField field.
Swela Jathar
Greenhorn

Joined: Aug 19, 2011
Posts: 22
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

Joined: Jun 13, 2009
Posts: 2153
    
    7
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
 
subject: shortcut key for label
 
Similar Threads
call batch or executable script with shortcut key in Win XP
javascript events and global shortcuts
Eclipse 2 - Java Build Path
Combo box focus problem
Mneumonic for editable JComboBox