JTextField

The JTextfield control us to edit one line of text.

JTextfield()
JTextfield(int cols)
JTextfield(String s,int cols)
JTextfield(String s)

Here, s is the String to be displayed within the textfield.Here, cols is the number of columns in the textfield.

Program

tyu

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;

class Frame extends JFrame {
    
    Frame()
    {
        setTitle("JTextField");
        setLayout(new FlowLayout());
        setJTextFields();
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJTextFields()
    {
        JLabel     jl1 = new JLabel("JTextField01");
        add(jl1);
        JTextField jt1 = new JTextField(10);
        add(jt1);
        JLabel     jl2 = new JLabel("JTextField02");
        add(jl2);
        JTextField jt2 = new JTextField("Hajsof",10);
        add(jt2);
        JLabel     jl3 = new JLabel("JTextField03");
        add(jl3);
        JTextField jt3 = new JTextField("Saravan",10);
        jt3.setEditable(false);
        add(jt3); 
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
        Frame frame = new Frame();
    }
}

Leave a Comment