Studyon Minte9.com
Java SE




Window Listener




package testexample; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Test extends JFrame { public static void main(String[] args) { JFrame frame = new Test(); frame.setBounds(200, 200, 300, 200); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setVisible(true); } public Test() { JTextField inputText = new JTextField("No focus", 10); final JTextField inputText2 = new JTextField(15); addWindowListener( new WindowAdapter() { @Override public void windowOpened( WindowEvent e ){ inputText2.requestFocus(); } }); JPanel panel = new JPanel(); panel.add(inputText); panel.add(inputText2); setLayout(new FlowLayout()); add(panel); } }
 


http://stackoverflow.com/questions/6723257/how-to-set-focus-on-jtextfield