My Escape key is not working

Hi,

I am Meena.

I am doing a project using NetBeans and MS-Access.

When I run my project a internal framed named login loaded on the jdesktoppane which in JFrame.

So in the login internal frame i used two buttons one for Sign-in and another for sign out.

So I combined the Sign-in button with Enter key and Sign-out button with Escape key by the following coding.

I wrote the following coding in LoginInternalFrame->properties->enabled->advanced->Generate PreIntialization Code.

Action EscFromLogin=new AbstractAction()

{

publicvoid actionPerformed(ActionEvent e)

{

jButton2.doClick();

}

};

Action OkFromLogin=new AbstractAction()

{

publicvoid actionPerformed(ActionEvent e)

{

jButton1.doClick();

}

};

getRootPane().getInputMap(jButton2.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0,false),"Esc_in_Login");

getRootPane().getActionMap().put("Esc_in_Login",EscFromLogin);

getRootPane().getInputMap(jButton1.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,false),"Ok_in_Login");

getRootPane().getActionMap().put("Ok_in_Login",OkFromLogin);

In the above coding Enter key works well no problem.that is when I press the Enter key ,it combined with Sign-in button and works well.

But when I press Escape key,it doesnot combined with Sign-off button.

that is nothing is happening when I press Esc key.

So i change the Escape key and test with F1 then F2 then F3 all are combined with Sign-off button and works well.But only the escape key is not working.

But I have so many internal frames .In all internalframes my esc key works well.But not in the first inter frame(login internalframe)

I couldnot understand the reason.

Will you please help me to solve.

Thank you so much.

Meena

[2529 byte] By [myque-ans@soona] at [2007-10-2 18:09:00]
# 1

Hi Meena,

some other way also u can solve that problem.Inside KeyPressed function u can check event is coming from Esc key or Enter key.

public void keyPressed(KeyEvent ke) {

if(ke.getKeyChar()==KeyEvent.VK_ENTER)

{

button1.doClick();

}

if(ke.getKeyChar==KeyEvent.VK_ESCAPE

{

button2.doClock();

}

}

Pradeep_M_Va at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 2
Can you write the list of components you have in the login internal frame? And, if the button sing-out has the focus and you press the esc key, the action is executed?
dcastannona at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi,

Thank you so much for your reply.

I tried the following

private void formKeyPressed(java.awt.event.KeyEvent evt) {

if(evt.getKeyChar()==KeyEvent.VK_ESCAPE)

{

jButton2.doClick();

}

}

I write this coding under my internal frame key pressed event.

But I didnot get any improvement.Still Esc key is not working.

The focus is in the password textfield which is in the same internal frame.Depends upon my spec,the cursor should be in password textfield.So I give the control to that text field when the project is running.

Will you please explain me where is the fault ?

Thank you so much.

Meena.

myque-ans@soona at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 4

Hi,

thank you so much for your reply.

In the Login internalframe I put the following

1.one jPanel.

2.one jTextField for Username(contains the userename)

3.one jTextField for password.

4.one jButton for Sign-in

5.one jButton for Sign-off

the cursor is in password textField.

If I press enter key it works well

But if I press Esc key nothing is happening.

So in my coding I chnge the escape key in to F1 ,F2,F3.

All or working that is if I press F1 the corresponding escape action which is in jButton2 actionPerformed executed well.

But if I use escape key, not work.

So i am confused.

will you please explain me where is the fault and a way to solve?

Thank you so much.

Regards

meena

myque-ans@soona at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 5

mmm, i'm doing some tests and the case is working for me... The reason F1,F2 keys works while ESC don't is that some component is "eating" the ESC key. Probably your password textField, but it is not its default behaviour. For example, try to replace the textField with a FormattedTextField, write something into it and press ESC, this first ESC is consumed by the FormattedTextField, if you press ESC a second time the FormattedTextField not consume it, so the ESC keystroke processing is given to the rest of the componentes until one of they consume it (basically). So, how can you solve th problem? Try to determine which component is the "escape-eater". Once you detected it try to determine which properties are set and if this properties can alter the keyboard mapping. The problem can be difficult to repeat for us because the look and feel, java version, etc. can affect the system behaviour too. A global hook to ESC can also be the reason (maybe esc key it's not reaching ths components), try to override ProcessKeyBindings and log the results....

dcastannona at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 6

Hi,

Thank you so much for your reply.

It is a difficult but nice reply.

So I am going to read the reply two to three times and understand line by line then I try.

After getting something positive results or some problems I come again and tell the details.

Thank you so much.

Meena.

myque-ans@soona at 2007-7-13 19:28:40 > top of Java-index,Desktop,Core GUI APIs...