wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
Spooky tabindex problem...
Regarding JDialog
Opening a frame from a dialog
Putting back JDialog
question about the jcombox focus