aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "to get default focus " Watch "to get default focus " New topic
Author

to get default focus

shilpa patil
Greenhorn

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
Greenhorn

Joined: Jan 29, 2006
Posts: 6
Thanks..Michael
it worked
Thanks again for the prompt reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to get default focus