Add JTextField into JFrame

Source code below will show you how to add text field in JFrame. There are two example of text field. First is without initial text. Second is text field with initial text.

***********************************************************************
COMPLETE SOURCE CODE FOR : AddJTextFieldIntoJFrame.java
***********************************************************************


import javax.swing.JTextField;
import javax.swing.JFrame;

import java.awt.GridLayout;

public class AddJTextFieldIntoJFrame
{
public static void main(String[]args)
{
//Create JTextField with no initial text
JTextField textField1=new JTextField();

//Create JTextField with initial text ( Put your text here )
JTextField textField2=new JTextField("Put your text here");

//Create a JFrame with title ( Put JTextField into JFrame )
JFrame frame=new JFrame("Put JTextField into JFrame");

//Set layout for JFrame
frame.setLayout(new GridLayout(2,1,1,3));

//Add first JTextField into JFrame
frame.add(textField1);

//Add second JTextField into JFrame
frame.add(textField2);

//Set close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set size for JFrame
frame.setSize(500,100);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

RELAXING NATURE VIDEO