Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to get default focus

 
shilpa patil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..Michael
it worked
Thanks again for the prompt reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic