Skip to content
February 6, 2009 / Narayan

Text Field

The Text Field in java specially instantiated from JTextField by importing
Here now we are gonna make a simple textfield with definite size and it’s position in JFrame.

First of all we should know dat JFrame, JPanel, JTextField are the classes of the java.swing.These all classes are included in Java swing hierarchy.Now to code for textfield we’ll need the Layout and dat will be defined soon by ourself.In Defaut the java uses it’s own Layout for textbox.The main code for defining the position and size is given below:
textbox_name.setBounds(x_axis,y_axis, width, height);

The detail code of the text box is given below

//Import directives
import javax.swing.*;

public class Text{

static JPanel panel;
static JFrame frame;

int x_axis = 100;
int y_axis = 10;
int width = 100;
int height = 20;
int column = 4;

JLabel label;
JTextField textBox;

    public Text() {

        frame = new JFrame("test");
        panel = new JPanel();

        label = new JLabel("User");

        textBox = new JTextField(4);

        //looping for the textbox position and it's size
        for(int i = 0; i<10; i++){
                case 1:
                label.setBounds(x_axis,y_axis, width, height);
                case 2:
                textBox.setBounds((x_axis+40),y_axis, width, height);

        //controls panes

        frame.setSize(400, 100);


    public static void main (String[] args) {
        Text finalObject = new Text();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: