wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Acheiving Focus using EnterKey Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Acheiving Focus using EnterKey " Watch "Acheiving Focus using EnterKey " New topic

Acheiving Focus using EnterKey

Udaya Bascar
Ranch Hand

Joined: Jun 18, 2002
Posts: 32
In my Application there are 5 text fields
if i press enter key on first text field i want
the control transfer to 2nd text field
not using tab
i have used key listener for trapping enter key
and the Component is JTextField
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
When you trap the enter key, check which text field it was recieved from and then have the next field request the key focus.
Or if you will be using fields like this alot and want this feature, subclass the JTextField and include a field that knows the next component you want to receive the keyfocus. Then when you "enter", the current component knows who to tell to request the keyfocus without external coding...
Udaya Bascar
Ranch Hand

Joined: Jun 18, 2002
Posts: 32
my code
JTextField jtf1,jtf2;
jtf1=new JTextField();
jtf2=new JTextField();
jtf1.addKeyListener(new KeyAdapter()
public void keyTyped(KeyEvent e)
if ( e.getKeyCode() == 10 )
its ok
It is sorta covered in the JavaRanch Style Guide.
subject: Acheiving Focus using EnterKey
Similar Threads
Capturing "Enter Key" Value in Javascript
Listening for the enter key in an JTextField?
How to submit a form from a como box - with enter key
validations coding..
How can a TextField get focus?