jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes KeyListener && KeyEvents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "KeyListener && KeyEvents" Watch "KeyListener && KeyEvents" New topic

KeyListener && KeyEvents

sinasi susam
Ranch Hand

Joined: Jul 15, 2005
Posts: 67
Hello ,
My problem had two various things.

I wanna dedect when tab key is pressed or typed or released.
i tried ;

I dont even get the first message when i type tab key.
Its moving to another focusable component and seems No Keyevent fired.

How can i dedect if tabkey is typed?

2-When its typed i want it's function not to be performed.
I mean it should not go to next focusable field.
But i want to dedect it when its typed.Because i want to make some operations suc as jdbc and after that either i am going to send the cursor to next focusable field or another one or in case of failure of a select sql , i wont permit the user pass the field which is tabkey pressed.

User must not move to another field without entering a valid value that is existing in db table..

thank you.
[ February 23, 2006: Message edited by: sinasi susam ]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
It sounds like you want the contents of a field to be verified when the user tries to shift focus off that field. That is a job for InputVerifier. Since focus management grabs tab key events they never make it to the text field. And as a rule of thumb I suggest that you shouldn't write KeyListeners -- they are almost always wrong, or there is a better solution not involving them.

There is no emoticon for what I am feeling!
sinasi susam
Ranch Hand

Joined: Jul 15, 2005
Posts: 67
Thank you for answer.
However How can i manage the focusing after the textfield is verified?
Cursor is moving to next focusable component.
I also want to manage its movement.And some other operations..

I imagine it to be like this,

User is going to hit the tab key, and secondly it will connect to an application server.App. server is going to run an sql statement and will return the results in form of text documents such as ;

focus [component_name]
visible [component_name]

And after that i will get the results and process with a parser..
If not any movement exists cursor will not go anywhere either..

its like this..

[ February 23, 2006: Message edited by: sinasi susam ]
[ February 23, 2006: Message edited by: sinasi susam ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
see if this gets you what you want

Nageswar Kakolla
Ranch Hand

Joined: Jan 16, 2006
Posts: 71
You have to implement KeyLitener interface and implement the overridden methods void keyTyped(), void keyPressed(), void keyRelease() methods
I agree. Here's the link: http://aspose.com/file-tools
subject: KeyListener && KeyEvents
jQuery in Action, 3rd edition