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.
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.
just interested to know how menu, toolbar, border, combobox, button, awt.frame, diaolg, popup and scrollpane,
has anything to do with the subject line?
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.
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.