Re: JOptionPane focus
- From: Ian Wilson <scobloke2@xxxxxxxxxxxxx>
- Date: Thu, 27 Apr 2006 11:53:04 +0100
Michael Dunn wrote:
"Ian Wilson" wrote
When I use JOptionPane's static methods to display some JTextFields, initial focus is on one of the buttons, is it possible to set initial focus to the JTextField?
<example code snipped for brevity>
JPanel panel = new JPanel();
final JTextField nameField = new JTextField(10);//<-----final
javax.swing.SwingUtilities.invokeLater(new Runnable() {//<-----add
public void run() { nameField.requestFocusInWindow(); }});//<----add
JPasswordField passwordField = new JPasswordField(10);
Thanks for the quick response Michael, that did the trick.
I can't say I understand this, (e.g. why 'final', how does invokeLater tie in with the chronological sequence in which GUI objects appear and are allocated focus? I'm surprised that the nameField.requestFocus isn't superceded by something similar (e.g. OKButton.requestFocus) being done chronologically later by the JOptionPane constructor. Is there any recommended reading material that might help me understand it?
.
- Follow-Ups:
- Re: JOptionPane focus
- From: Michael Dunn
- Re: JOptionPane focus
- References:
- JOptionPane focus
- From: Ian Wilson
- Re: JOptionPane focus
- From: Michael Dunn
- JOptionPane focus
- Prev by Date: Re: JOptionPane focus
- Next by Date: Re: Execution problem with jhotdraw
- Previous by thread: Re: JOptionPane focus
- Next by thread: Re: JOptionPane focus
- Index(es):