Below code shows how to create a JTextField using Java Swing JTextField class.Note that JTextField class extends JTextComponent and implem...
Below code shows how to create a JTextField using Java Swing JTextField class.Note that JTextField class extends JTextComponent and implements interface SwingConstants.
/** * * @author Eric * Blog:www.techoverload.net */ import javax.swing.JFrame; import javax.swing.JTextField; import java.awt.Dimension; public class JTextFieldExample { public JFrame frame; public JTextField field; JTextFieldExample() { frame=new JFrame("JTextField Example"); //create JTextField object field=new JTextField(); field.setBounds(10, 10, 200, 20); frame.add(field); //======================= frame.setSize(new Dimension(300,300)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(null); frame.setVisible(true); } public static void main(String args[]) { new JTextFieldExample(); } }