java.awt

Class TextField

public class TextField extends TextComponent

This class implements a single line text entry field widget
Nested Class Summary
protected classTextField.AccessibleAWTTextField
Constructor Summary
TextField()
Initializes a new instance of TextField that is empty and has one column.
TextField(String text)
Initializes a new instance of TextField containing the specified text.
TextField(int columns)
Initializes a new instance of TextField that is empty and has the specified number of columns.
TextField(String text, int columns)
Initializes a new instance of TextField with the specified text and number of columns.
Method Summary
voidaddActionListener(ActionListener listener)
Addes a new listener to the list of action listeners for this object.
voidaddNotify()
Notifies this object that it should create its native peer.
booleanechoCharIsSet()
Tests whether or not this text field has an echo character set so that characters the user type are not echoed to the screen.
AccessibleContextgetAccessibleContext()
ActionListener[]getActionListeners()
Return all ActionListeners register to this TextField object as an array.
intgetColumns()
Returns the number of columns in the field.
chargetEchoChar()
Returns the character that is echoed to the screen when a text field is protected (such as when a password is being entered).
<T extends EventListener> T[]getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this TextField.
DimensiongetMinimumSize()
Returns the minimum size for this text field.
DimensiongetMinimumSize(int columns)
Returns the minimum size of a text field with the specified number of columns.
DimensiongetPreferredSize()
Returns the preferred size for this text field.
DimensiongetPreferredSize(int columns)
Returns the preferred size of a text field with the specified number of columns.
DimensionminimumSize()
Returns the minimum size for this text field.
DimensionminimumSize(int columns)
Returns the minimum size of a text field with the specified number of columns.
protected StringparamString()
Returns a debug string for this object.
DimensionpreferredSize()
Returns the preferred size for this text field.
DimensionpreferredSize(int columns)
Returns the preferred size of a text field with the specified number of columns.
protected voidprocessActionEvent(ActionEvent event)
Processes an action event by calling any registered listeners.
protected voidprocessEvent(AWTEvent event)
Processes the specified event.
voidremoveActionListener(ActionListener listener)
Removes the specified listener from the list of action listeners for this object.
voidsetColumns(int columns)
Sets the number of columns in this field to the specified value.
voidsetEchoChar(char echoChar)
Sets the character that is echoed when protected input such as a password is displayed.
voidsetEchoCharacter(char echoChar)
Sets the character that is echoed when protected input such as a password is displayed.

Constructor Detail

TextField

public TextField()
Initializes a new instance of TextField that is empty and has one column.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true,

TextField

public TextField(String text)
Initializes a new instance of TextField containing the specified text. The number of columns will be equal to the length of the text string.

Parameters: text The text to display in the field.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true,

TextField

public TextField(int columns)
Initializes a new instance of TextField that is empty and has the specified number of columns.

Parameters: columns The number of columns in the text field.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true,

TextField

public TextField(String text, int columns)
Initializes a new instance of TextField with the specified text and number of columns.

Parameters: text The text to display in the field. columns The number of columns in the field.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true,

Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Addes a new listener to the list of action listeners for this object.

Parameters: listener The listener to add to the list.

addNotify

public void addNotify()
Notifies this object that it should create its native peer.

echoCharIsSet

public boolean echoCharIsSet()
Tests whether or not this text field has an echo character set so that characters the user type are not echoed to the screen.

Returns: true if an echo character is set, false otherwise.

getAccessibleContext

public AccessibleContext getAccessibleContext()

getActionListeners

public ActionListener[] getActionListeners()
Return all ActionListeners register to this TextField object as an array.

Since: 1.4

getColumns

public int getColumns()
Returns the number of columns in the field.

Returns: The number of columns in the field.

getEchoChar

public char getEchoChar()
Returns the character that is echoed to the screen when a text field is protected (such as when a password is being entered).

Returns: The echo character for this text field.

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this TextField. FooListeners are registered using the addFooListener method.

Throws: ClassCastException If listenerType doesn't specify a class or interface that implements java.util.EventListener.

Since: 1.3

getMinimumSize

public Dimension getMinimumSize()
Returns the minimum size for this text field.

Returns: The minimum size for this text field.

getMinimumSize

public Dimension getMinimumSize(int columns)
Returns the minimum size of a text field with the specified number of columns.

Parameters: columns The number of columns to get the minimum size for.

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size for this text field.

Returns: The preferred size for this text field.

getPreferredSize

public Dimension getPreferredSize(int columns)
Returns the preferred size of a text field with the specified number of columns.

Parameters: columns The number of columns to get the preferred size for.

minimumSize

public Dimension minimumSize()

Deprecated: This method is deprecated in favor of getMinimumSize().

Returns the minimum size for this text field.

Returns: The minimum size for this text field.

minimumSize

public Dimension minimumSize(int columns)

Deprecated: This method is deprecated in favor of getMinimumSize(int).

Returns the minimum size of a text field with the specified number of columns.

Parameters: columns The number of columns to get the minimum size for.

paramString

protected String paramString()
Returns a debug string for this object.

Returns: A debug string for this object.

preferredSize

public Dimension preferredSize()

Deprecated: This method is deprecated in favor of getPreferredSize().

Returns the preferred size for this text field.

Returns: The preferred size for this text field.

preferredSize

public Dimension preferredSize(int columns)

Deprecated: This method is deprecated in favor of getPreferredSize(int).

Returns the preferred size of a text field with the specified number of columns.

Parameters: columns The number of columns to get the preferred size for.

processActionEvent

protected void processActionEvent(ActionEvent event)
Processes an action event by calling any registered listeners. Note to subclasses: This method is not called unless action events are enabled on this object. This will be true if any listeners are registered, or if action events were specifically enabled using enableEvents().

Parameters: event The event to process.

processEvent

protected void processEvent(AWTEvent event)
Processes the specified event. If the event is an instance of ActionEvent then processActionEvent() is called to process it, otherwise the event is sent to the superclass.

Parameters: event The event to process.

removeActionListener

public void removeActionListener(ActionListener listener)
Removes the specified listener from the list of action listeners for this object.

Parameters: listener The listener to remove from the list.

setColumns

public void setColumns(int columns)
Sets the number of columns in this field to the specified value.

Parameters: columns The new number of columns in the field.

Throws: IllegalArgumentException If columns is less than zero.

setEchoChar

public void setEchoChar(char echoChar)
Sets the character that is echoed when protected input such as a password is displayed.

Parameters: echoChar The new echo character.

setEchoCharacter

public void setEchoCharacter(char echoChar)

Deprecated: This method is deprecated in favor of setEchoChar()

Sets the character that is echoed when protected input such as a password is displayed.

Parameters: echoChar The new echo character.