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:
> Im pasting the getLogonPanel method from my login class:
My car won't start.
Here's the front wheel, what's the problem?
Joined: Mar 17, 2009
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'
Joined: Jun 09, 2003
> 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
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.