Results 1 to 7 of 7
Thread: Key Listener
- 11-22-2011, 01:15 PM #1
Senior Member
- Join Date
- Aug 2011
- Posts
- 251
- Rep Power
- 10
Key Listener
Hello everyone,
I'm trying to add a Key Listener that will "listen" to a single key when it pressed on a GUI.
I looked for guides and all of them adding the key listener to an instance such as TextArea1.addKey~~
I want they key Listener to work even if the Jar file is minimized and I'm doing somthing else and not only when i'm on a specific textare or somthing.
Any help will be appreciated.
- 11-22-2011, 01:44 PM #2
Re: Key Listener
Java can't detect key events when it does not have the focus.
- 11-22-2011, 02:35 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 251
- Rep Power
- 10
Re: Key Listener
So if I'm focused on the Jar window and I want to add a key Listener to a GUI swing for example how would I do that?
Again, all the tutorials showed that the key listener is attached to an instance.. I don't want that .. I want the whole window!
Thanks.
edit: hmmm waitt!! maybe to the panel?I wish I could have now a jde to test it.
edit2: I tried to add a Key Listener to the frame and nothing happend and also to the frame.Last edited by tnrh1; 11-22-2011 at 02:47 PM.
- 11-22-2011, 02:47 PM #4
Re: Key Listener
I want the whole window!
- 11-22-2011, 03:03 PM #5
Senior Member
- Join Date
- Aug 2011
- Posts
- 251
- Rep Power
- 10
Re: Key Listener
The JFrame class.
The class sign looks like this: public class ClassName extends JFrame implements KeyListener
And I added this code:
addKeyListener(this);
And the unimplemented methods keyTyped etc ..
- 11-22-2011, 03:50 PM #6
Re: Key Listener
Have you looked at Key Binding? That can be easier to use and more reliable.
- 11-22-2011, 04:44 PM #7
Senior Member
- Join Date
- Aug 2011
- Posts
- 251
- Rep Power
- 10
Similar Threads
-
key listener
By nikkka in forum New To JavaReplies: 8Last Post: 04-23-2011, 10:36 AM -
J2ME sms listener
By bharani in forum CLDC and MIDPReplies: 4Last Post: 11-21-2010, 07:33 PM -
Tab Listener
By teckno101 in forum AWT / SwingReplies: 2Last Post: 09-29-2009, 10:40 PM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-21-2008, 12:07 AM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-10-2008, 03:00 AM
Bookmarks