• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Acheiving Focus using EnterKey

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my code
JTextField jtf1,jtf2;
jtf1=new JTextField();
jtf2=new JTextField();
jtf1.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
if ( e.getKeyCode() == 10 )
{
jtf2.requestFocus();
}
}
});
its ok
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic