Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SETTING FOCUS ON A TEXT FIELD

 
RAY CARNES
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to put the pointer (or hatever it's called in a text field) onto the text field so the user can just start typing. I haven't been able to find the method to do this.
 
Todd M Bush
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To give a component the default focus when the window first opens, you must use the component.requestFocus() command in the window opened event. Like this....
frame.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent we) {
textfield.requestFocus();
}
});
hope this helps
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic