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

KeyListener not working for JLabel.

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic