All About Class TextField in AWT in Java



TextField is a single line text input box.So it is a component that presents user with a single editable line of text.The constructors of this class allow us to create textfileds of a specific character width with default values.The text is editable using keys and mouse selections.This class can be used to accept text to echo it or hide it the echo(like password).It is derived from TextComponent hence it can receive text Value changed events as well as keyPress and FocusEvents.
The class structure of TextField is given as:


public class java.awt.TextField extends java.awt.TextComponent{
//constructors
public TextFiled();//default constructor,creates an empty TextFiled.
public TextFiled(int numberOfCharacters); //constructs a new textfield with the specified number of character wide.
public TextFiled(String initialText);//constructs a new textfield initialized with specified text
public TextFiled(String initialText,int numberOfCharacters);//constructs a new textfield initialized with 
//specified text wide enough to hold the specified number of characters.
//methods
public void setEchoCharacter(char c);//mostly used in password field.
public void addNotify();
public boolean echoCharIsSet();
public String getText();//returns the current text in the box.
public void setTest(String text);//sets text to the text field.
public int getColumns();
public char getEchoChar();
protected String paramString();
public Dimension minimumSize();
public Dimension minimumSize(int cols);
public Dimension preferredSize();
public Dimension preferredSize(int cols);
public void setEditable(boolean option);//determines if the field is editable or not
public String select(start,end);//select text characters between specified start and end characters
}
 
Example:

TextField txt1=new TextFiled();
TextField txt1=new TextFiled(20);
TextField txt1=new TextFiled("Enter your Name");
TextField txt1=new TextFiled("Enter your Name",20);
 
All About Class TextField in AWT in Java All About Class TextField  in AWT in Java Reviewed by Animesh Chatterjee on November 20, 2018 Rating: 5

No comments:

Powered by Blogger.