Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JTextField Class

JTextField class is used to create a text box and takes single line of text as input. It is most widely used text component. JTextField having three constructors, such as:

Let's see an example for displaying an image on the button.

JTextField(int columns)
JTextField(String str, int columns)
JTextField(String str)
Let's see an example using JTextField class:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JTextFieldDemo extends JFrame 
{
	public JTextFieldDemo() 
	{
		JTextField jf = new JTextField(20);	           //creating JTextField. 
		add(jf);				//adding JTextField to frame. 
		setLayout(new FlowLayout());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300, 300);
		setVisible(true);
	}
	public static void main(String[] args) 
	{
		new JTextFieldDemo();
	}
}
Output:

pic


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext