Java examples for Swing:JTextField
A JTextField can display and/or edit one line of plain text.
Constructors of the JTextField Class
Constructor | Description |
---|---|
JTextField() | Creates a JTextField with default values for initial text, number of columns, and document. |
JTextField(Document document, String text, int columns) | Creates a JTextField with the specified document as its model, text as its initial text, and columns as its number of columns. |
JTextField(int columns) | Creates a JTextField with the specified columns as its number of columns. |
JTextField(String text) | Creates a JTextField with the specified text as its initial text. |
JTextField(String text, int columns) | Creates a JTextField with the specified text as its initial text and columns as its number of columns. |
import javax.swing.JTextField; public class Main { public static void main(String[] args) { // Create an empty JTextField JTextField emptyTextField = new JTextField(); // Create a JTextField with an initial text of Hello JTextField helloTextField = new JTextField("Hello"); // Create a JTextField with the number of columns of 20 JTextField nameTextField = new JTextField(20); }/*from w w w . j av a 2 s .c o m*/ }