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

KeyListener not working for JLabel.

 
Sharad Kharya
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on Swing application and not able to add keyListener on my JLabel component.
But mouseListener is working properly.

I need to add 3 keyboard events
1) Enter - To get inside label folder
2) Ctrl – need to perform ctrl+click operation.
3) Tab – to navigate from one Label to another.(and after browsing to the selected label user can press enter key)

Below is the code snippet

Please let me know who to resolve keyboard event handling issue properly here.

Thanks
Sharad>
 
K. Tsang
Bartender
Pie
Posts: 3222
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you try comment out the mouse listener part and see if key stuff works? If it doesn't probably something wrong inside those overridden methods. If not try put key listener in front of mouse listener. Oh shouldn't the label be focused before key actions are detected? Just a thought.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Below is the code snippet

just interested to know how menu, toolbar, border, combobox, button, awt.frame, diaolg, popup and scrollpane,
has anything to do with the subject line?

 
Paul Clapham
Sheriff
Pie
Posts: 20171
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sharad Golu wrote:Hi,
I am working on Swing application and not able to add keyListener on my JLabel component.
But mouseListener is working properly.

I need to add 3 keyboard events
1) Enter - To get inside label folder
2) Ctrl – need to perform ctrl+click operation.
3) Tab – to navigate from one Label to another.(and after browsing to the selected label user can press enter key)

I don't understand where the KeyListener comes into your design. You certainly don't need to listen for Tab keys, that's the job of the FocusListener for whatever component contains your JLabel. Likewise if the JLabel has focus, then pressing Enter will automatically do the same as if you clicked on the JLabel.

And I believe you would look for Ctrl-click in a MouseListener rather than a KeyListener.

I didn't look at any of your code because I don't think any of it was relevant (because of what I just posted above). But even if some of it was relevant, there was way too much of it. A small program with one or two labels would have sufficed. Anything else would just distract from the actual question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic