Make sure that my Text field has the focus when a JFrame is created
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JTextField; class MyFrame extends JFrame { JTextField field1; public MyFrame() { field1 = new JTextField(10); getContentPane().add("Center", field1); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { field1.requestFocus(); } }); pack(); setVisible(true); } } public class Main { public static void main(String[] argv) { MyFrame myFrame = new MyFrame(); } }