• JTextField Class

    JTextField Class

    The swing JTextField class is encapsulated by the JTextComponent class, which extends JComponent. It provides functionality that is common to Swing text components. One of its subclass is JTextField, which allows you to edit one line of text.

    Some of its constructors are shown here:


    JTextFields(int cols)

    JTextFields(String s, int cols)

    JTextFields(String s)

    Here s is the string to be presented, and cols is the number of columns In the text field.

    Example of JTextField control with JApplet in Swing

    JTextField Control in Swing Example

    JTextField Control in Swing Example

    /** <APPLET CODE = “JTextFieldExample.CLASS” WIDTH = 500 HEIGHT = 500″></APPLET>

    * */

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    public class JTextFieldExample extends JApplet implements ActionListener


    JTextField jtf1, jtf2;

    JLabel jl1, jl2;

    public void init()


    Container contentPane = getContentPane();

    contentPane.setLayout(new FlowLayout());

    jl1 = new JLabel(“Enter String : “);

    jtf1 =  new JTextField(15);

    jl2 = new JLabel(“See The Output :”);

    jtf2 = new JTextField(15);







    public void actionPerformed(ActionEvent ae)





    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *