Packages This Package Prev Next Index
§1.40 Class TextField
public class java.awt.TextField
extends java.awt.TextComponent (II-§1.39)
{
// Constructors
public TextField(); §1.40.1
public TextField(int cols); §1.40.2
public TextField(String text); §1.40.3
public TextField(String text, int cols); §1.40.4
// Methods
public void addNotify(); §1.40.5
public boolean echoCharIsSet(); §1.40.6
public int getColumns(); §1.40.7
public char getEchoChar(); §1.40.8
public Dimension minimumSize(); §1.40.9
public Dimension minimumSize(int cols); §1.40.10
protected String paramString(); §1.40.11
public Dimension preferredSize(); §1.40.12
public Dimension preferredSize(int cols); §1.40.13
public void setEchoCharacter(char c); §1.40.14
}
A text field is a component that presents the user with a single editable line of text.
For example, the following code code:
TextField tf1, tf2, tf3, tf4;
// a blank text field
tf1 = new TextField();
// blank field of 20 columns
tf2 = new TextField(20);
// Predefined text displayed
tf3 = new TextField("Hello!");
// Predefined text in 30 columns
tf4 = new TextField("Hello", 30);
produces the text fields shown below:
Every time the user types a key1 in the text field, AWT sends a key press event
(II-§1.14.15) and a key release event (II-§1.14.16) to the text field. These events' target
field is the button, and their key field is the key typed.
In addition, whether the user types the return key, AWT sends an action event
(II-§1.14.11) to the text field. This event's target is the text field, and its object is the string
contents of the text field; the string will not have a return character as its last character. An
application should override the action method (II-§1.10.1) of the text field or of one of its
containing windows in order to cause some action to occur.
TextField
public TextField()
- Constructs a new text field.
TextField
public TextField(int cols)
- Constructs a new text field the specified number of characters wide.
- Parameters:
cols
-
the number of character
TextField
public TextField(String text)
- Constructs a new text field initialized with the specified text.
- Parameters:
text
-
the text to be displayed
TextField
public TextField(String text, int cols)
- Constructs a new text field initialized with the specified text and wide
enough to hold the specified number of characters.
- Parameters:
text
-
the text to be displayed
cols
-
the number of characters
addNotify
public void addNotify()
- This method calls the createTextField method (II-§1.41.20) of this object's
toolkit (II-§1.10.20) in order to create a TextFieldPeer (II-§3.21) for this text
field. This peer allows the application to change the look of a text field
without changing its functionality.
- Most applications do not call this method directly.
- Overrides:
- addNotify in class Component (II-§1.10.2).
echoCharIsSet
public boolean echoCharIsSet()
- Returns:
- true if this text field has a character set for echoing; false otherwise.
- See Also:
- setEchoCharacter (II-§1.40.14)
getEchoChar (II-§1.40.8).
getColumns
public int getColumns()
- Returns:
- the number of columns in this text field.
getEchoChar
public char getEchoChar()
- Returns:
- the echo character for this text field.
- See Also:
- setEchoCharacter (II-§1.40.14)
echoCharIsSet (II-§1.40.6).
minimumSize
public Dimension minimumSize()
- Determines the minimum size of this text field. If the application has specified the number of columns for this text field, and it is greater than zero,
then this text field's peer's minimumSize method (II-§3.21.1) is called with
the number columns in order to determine the minimum size.
- If this text field does not have a peer, or if the number of columns specified
by the application is less than or equal to zero, the superclass's minimumSize method (II-§1.10.40) is called to determine the minimum size.
- Returns:
- the minimum dimensions needed for this text area.
- Overrides:
- minimumSize in class Component (II-§1.10.40).
minimumSize
public Dimension minimumSize(int cols)
- Determines the minimum size of a text field with the specified number of
columns. This text field's peer's minimumSize method (II-§3.21.1) is called
with the number of columns in order to determine the minimum size.
- If this text field does not have a peer the superclass's minimumSize method
(II-§1.10.40) is called to determine the minimum size.
- Parameters:
cols
-
the number of columns
- Returns:
- the minimum dimensions needed to display a text area with the specified number of columns.
paramString
protected String paramString()
- Returns the parameter string representing the state of this text field. This
string is useful for debugging.
- Returns:
- the parameter string of this text field.
- Overrides:
- paramString in class TextComponent (II-§1.39.6).
preferredSize
public Dimension preferredSize()
- Determines the preferred size of this text field. If the application has specified the number of columns for this text field, and it is greater than zero,
then this text field's peer's preferredSize method (II-§3.21.2) is called with
the number of columns in order to determine the preferred size.
- If this text field does not have a peer, or if the number of columns specified
by the application is less than or equal to zero, the superclass's preferredSize
method (II-§1.10.53) is called to determine the preferred size.
- Returns:
- the preferred dimensions needed for this text field.
- Overrides:
- preferredSize in class Component (II-§1.10.53).
preferredSize
public Dimension preferredSize(int cols)
- Determines the preferred size of a text field with the specified number of
columns. This text field's peer's preferredSize method (II-§3.21.2) is called
with the number columns in order to determine the preferred size.
- If this text field does not have a peer the superclass's preferredSize method
(II-§1.10.53) is called to determine the preferred size.
- Parameters:
cols
-
the number of columns
- Returns:
- the preferred dimensions needed to display the text field with the
specified number of columns.
setEchoCharacter
public void setEchoCharacter(char c)
- Sets the echo character for this text field. Any character that the user types
in the text field is echoed in this text field as the echo character.
- An echo character is useful for fields where the user input shouldn't be
echoed to the screen such as in the case of a text field for typing in a password.
- Parameters:
c
-
the echo character for this text field
- See Also:
- echoCharIsSet (II-§1.40.6)
getEchoChar (II-§1.40.8).
1
In Java 1.0, the AWT does not send mouse or focus events to a text area. In Java
1.1, the AWT sends the text area all mouse, keyboard, and focus events that occur
over it.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com