Connection a keylistener to a Dialog or Frame.
From: Kid (bo_kid_at_yahoo.com)
Date: 02/24/04
- Next message: Kleopatra: "Re: Trouble with KeyListeners in 1.4.2"
- Previous message: ak: "Re: Debugging Swing Code"
- Next in thread: Kleopatra: "Re: Connection a keylistener to a Dialog or Frame."
- Reply: Kleopatra: "Re: Connection a keylistener to a Dialog or Frame."
- Reply: Andrew Chase: "Re: Connection a keylistener to a Dialog or Frame."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Feb 2004 04:08:45 -0800
Hello,
I'm trying to make my GUI application react to keyevents,
but I'm having a hard time making my Dialog (also tried with Frame)
react to keyevents.
I have the following rows in my ctor (for Dialog):
start of ctor
..
..
// Listen to keys.
this.setFocusable(true);
this.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
dialogKeyPressed(evt);
}
});
..
..
end of ctor
And I have:
private void dialogKeyPressed(java.awt.event.KeyEvent evt) {
System.err.println("Dialog Frame registered KEY PRESSED!");
}
But the method is never called and the error message never shows (I've
tried pressing ALOT of keys)!
Could someone please tell me what I'm doing wrong!!??
Right now I'm using a workaround where I connect the keyevent to a
certain component on the dialog, then I have to click on the component
to get the focus and finally I can receive keyevents from this
component.
But this is not what I want! I want my application to react to certain
F-keys no matter which component is focused.
Thanks for any kind of tips or guides.
/Bo
- Next message: Kleopatra: "Re: Trouble with KeyListeners in 1.4.2"
- Previous message: ak: "Re: Debugging Swing Code"
- Next in thread: Kleopatra: "Re: Connection a keylistener to a Dialog or Frame."
- Reply: Kleopatra: "Re: Connection a keylistener to a Dialog or Frame."
- Reply: Andrew Chase: "Re: Connection a keylistener to a Dialog or Frame."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]