This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting initial focus in a Model JDialog

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to set the initial focus in a JDialog to a JButton that is near
the bottom of the dialog. This never seems to work. Focus always goes
to the first field. Anyone have any ideas.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
setVisible(true);
button.requestFocus();//next line, after the dialog is visible

<edit follows>
just realised above won't work when modal is true.
here's a bit of a workaround (include in your constructor)
you might have to adjust the 250 'lag' to suit


[ January 25, 2005: Message edited by: Michael Dunn ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic