Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General 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