This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Setting initial focus in a Model JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting initial focus in a Model JDialog" Watch "Setting initial focus in a Model JDialog" New topic
Author

Setting initial focus in a Model JDialog

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
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

Joined: Jun 09, 2003
Posts: 4632
...
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting initial focus in a Model JDialog