A tour of swing
JTextField allows editing/displaying of a single line of text. New features include the ability to justify the text left, right, or center, and to set the text’s font. When the user types data into them and presses the Enter key, an action event occurs. If the program registers an event listener, the listener processes the event and can use the data in the text field at the time of the event in the program.
JTextField is an input area where the user can type in characters. If you want to let the user enter multiple lines of text, you cannot use Jtextfield’s unless you create several of them. The solution is to use JTextArea, which enables the user to enter multiple lines of text.
Constructors:
JTextField() -
Constructs a new TextField.
JTextField(Document doc, String text, int columns) -
Constructs a new JTextField that uses the given text storage model and the given number of columns.
JTextField(int columns) -
Constructs a new empty TextField with the specified number of columns.
JTextField(String text) -
Constructs a new TextField initialized with the specified text.
JTextField(String text, int columns) -
Constructs a new TextField initialized with the specified text and columns.
Source Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JTextFieldDemo extends JFrame {
JTextField jtfText1, jtfUneditableText;
String disp = "";
TextHandler handler = null;
public JTextFieldDemo() {
super("TextField Test Demo");