This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am trying to disable/remove the enter key keyEvent. I'm adding a logonPanel (not created by me) to a loginFrame which I created.
In the logonPanel class, the submit button has a KeyListener which checks for enter key and eventually triggers an Actions interface method which I have overriden.
For incorrect logins a JOptionPane window pops up and asks to retry login and then hitting enter triggers the 'YES_OPTION'. The problem is that the Enter key event triggers down to the underlying frame and onOk gets triggered again and the JOptionPane pops up again (since the username and password havent been changed yet) and this vicious cycle continues as long as i hit 'enter' or until I use my mouse to click the 'YES_OPTION'
Im pasting the getLogonPanel method from my login class:
How can I solve this problem?
Thanks
Priya
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> Im pasting the getLogonPanel method from my login class:
My car won't start.
Here's the front wheel, what's the problem?
priya thomas
Greenhorn
Joined: Mar 17, 2009
Posts: 15
posted
0
Hi Michael,
I thought I gave a pretty comprehensive explanation. Do you want me to explain a bit more?
priya thomas wrote:
The problem is that the Enter key event triggers down to the underlying frame and onOk gets triggered again and the JOptionPane pops up again (since the username and password havent been changed yet) and this vicious cycle continues as long as i hit 'enter' or until I use my mouse to click the 'YES_OPTION'
Priya
Thanks,
Priya
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> I thought I gave a pretty comprehensive explanation.
so did I - the car won't start - no more explanation required.
if you want me to bring in the whole car (instead of just the front wheel),
so you can see exactly what the problem is, just ask
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1788
2
posted
0
In the logonPanel class, the submit button has a KeyListener which checks for enter key
Unfortunately as I mentioned earlier, the LogonPanel class is not mine. From my login class I only have access to an interface:
Implementing the functions onOk and onCancel will allow me to achieve functionality for the Submit and Cancel buttons of my login frame.
The buttons are using an action listener and a key listener (for users who prefer using the keyboard to the mouse)
Ideally I would like to remove KeyListeners on the JOptionPane , since it is the enter key pressed on the YES_OPTION that is causing the problem, but that isnt possible.
I can understand it is difficult to understand the scenario without the SSCCE. Let me rather ask a general button question:
If you don't have access to the button event handlers for a generic class, and you know one of the button event handlers is a keylistener which checks for 'enter' key triggers, is it possible from your class to remove the 'enter' key keyEvent? (I read up a little about inputMaps and removeKeyListener() function, but I'm not sure if that is the way to go)
Also i see that we can just put e.consume() in the keyPressedEvent where KeyEvent e is the enter keyEvent, but that's no use in my case since I'm using pre-written eventHandlers.