This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes to get default focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "to get default focus " Watch "to get default focus " New topic

to get default focus

shilpa patil

Joined: Jan 29, 2006
Posts: 6
hello all,
I am having a window with a textField.
I want whenever this window is shown , focus should be on this textfield
How can I do this.
Thanks in advance. :roll:
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
textfield.requestFocusInWindow() is the method, but if you are talking about
when the program first opens, the method must be called after the program's
visibility is set to true.

if you are using 1.5, there have been some changes to the focus subsystem that
causes the above method not to work properly. in this case try wrapping the
method in a SwingUtilities.invokeLater(), or, as a last resort, use a timer
with repeats set to false.
shilpa patil

Joined: Jan 29, 2006
Posts: 6
it worked
Thanks again for the prompt reply
I agree. Here's the link:
subject: to get default focus
It's not a secret anymore!