Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

swings  RSS feed

 
shiva kumar nanda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
can anybody help in finding out solution to how to set the default focus of the JtextField to gain ,where the component is in Jpanel
thanks
shiva
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[textField].requestFocusInWindow();

if you are having trouble focusing the component when the app first starts,
add a componentListener to the textField, and in componentShown() add the line

[EDIT]
forgot to add that requestFocusInWindow() needs the component to be visible
i.e. after the frame/whatever is visible
[ May 17, 2007: Message edited by: Michael Dunn ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!