This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Making control have initial focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making control have initial focus" Watch "Making control have initial focus" New topic
Author

Making control have initial focus

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
I don't see how to see how to set the initial focus of a JTextField in a JFrame after the JFrame loads.
I want to have focus already be inside the first text field.
There should be an easy way to set the initial focus, but I haven't found it. This would be analogous to setting the "Tab-Order" in Microsoft products.
I've tried things like:
jTextField.setFocusCycleRoot(true);
TextField.requestFocus();
But nothing works.
Any ideas?
Thanks.
-- Mike
Raj K
Greenhorn

Joined: Sep 10, 2002
Posts: 1
Try this:
this.addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowOpened(WindowEvent e)
{
your_textfield.requestFocus();
}
}
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
The trick to it is to requestFocus() AFTER you have setVisible to true, not before. It seems to be negated if you setVisible to true after you request focus.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Yes, using WindowAdaptor worked.
Thank you!!!
-- Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making control have initial focus
 
Similar Threads
Initial focus
setting focus on a component
Can't Focus On JPanel
Can i see i a field have focus !
Setting initial focus in a Model JDialog