APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public non-sealed Class TextArea

extends TextComponent
Class Inheritance
Imports
java.awt.peer.TextAreaPeer, java.io.IOException, .ObjectInputStream, .Serial, java.util.HashSet, .Set, javax.accessibility.AccessibleContext, .AccessibleState, .AccessibleStateSet

A TextArea object is a multi-line region that displays text. It can be set to allow editing or to be read-only.

The following image shows the appearance of a text area:

A TextArea showing the word
'Hello!'

This text area could be created by the following line of code:


new TextArea("Hello", 5, 40);

Author
Sami Shaio
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
TextArea.AccessibleAWTTextArea

This class implements accessibility support for the TextArea class.

Field Summary

Modifier and TypeField and Description
private static Set<AWTKeyStroke>
backwardTraversalKeys

Cache the Sets of forward and backward traversal keys so we need not look them up each time.

private static final String
pack-priv int
columns

The number of columns in the TextArea.

private static Set<AWTKeyStroke>
forwardTraversalKeys

Cache the Sets of forward and backward traversal keys so we need not look them up each time.

private static int
pack-priv int
rows

The number of rows in the TextArea.

public static final int
SCROLLBARS_BOTH

Create and display both vertical and horizontal scrollbars.

public static final int
SCROLLBARS_HORIZONTAL_ONLY

Create and display horizontal scrollbar only.

public static final int
SCROLLBARS_NONE

Do not create or display any scrollbars for the text area.

public static final int
SCROLLBARS_VERTICAL_ONLY

Create and display vertical scrollbar only.

private int
scrollbarVisibility

Determines which scrollbars are created for the text area.

private static final long
serialVersionUID

Hides java.awt.TextComponent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
private int
textAreaSerializedDataVersion

The textArea Serialized Data Version.

Inherited from java.awt.TextComponent:
backgroundSetByClientCodeeditableselectionEndselectionStarttexttextListener

Constructor Summary

AccessConstructor and Description
public
TextArea()

Constructs a new text area with the empty string as text.

public
TextArea(String
the text to be displayed; if text is null, the empty string "" will be displayed
text
)

Constructs a new text area with the specified text.

public
TextArea(int
the number of rows
rows
,
int
the number of columns
columns
)

Constructs a new text area with the specified number of rows and columns and the empty string as text.

public
TextArea(String
the text to be displayed; if text is null, the empty string "" will be displayed
text
,
int
the number of rows
rows
,
int
the number of columns
columns
)

Constructs a new text area with the specified text, and with the specified number of rows and columns.

public
TextArea(String
the text to be displayed; if text is null, the empty string "" will be displayed
text
,
int
the number of rows; if rows is less than 0, rows is set to 0
rows
,
int
the number of columns; if columns is less than 0, columns is set to 0
columns
,
int
a constant that determines what scrollbars are created to view the text area
scrollbars
)

Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.TextComponent.addNotify.

Creates the TextArea's peer.

public void
append(String
the non-null text to append
str
)

Appends the given text to the text area's current text.

public synchronized void
appendText(String
the text to append
str
)
Deprecated As of JDK version 1.1, replaced by append(String).

Appends the given text to the text area's current text.

pack-priv String
constructComponentName()

Overrides java.awt.Component.constructComponentName.

Construct a name for this component.

public AccessibleContext

Returns:

an AccessibleAWTTextArea that serves as the AccessibleContext of this TextArea
getAccessibleContext
()

Overrides java.awt.TextComponent.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Returns the AccessibleContext associated with this TextArea.

public int

Returns:

the number of columns in the text area
getColumns
()

Returns the number of columns in this text area.

public Dimension

Returns:

the minimum dimensions required to display the text area with the specified number of rows and columns
getMinimumSize
(int
the number of rows
rows
,
int
the number of columns
columns
)

Determines the minimum size of a text area with the specified number of rows and columns.

public Dimension

Returns:

the preferred dimensions needed for this text area
getMinimumSize
()

Overrides java.awt.Component.getMinimumSize.

Determines the minimum size of this text area.

public Dimension

Returns:

the preferred dimensions required to display the text area with the specified number of rows and columns
getPreferredSize
(int
the number of rows
rows
,
int
the number of columns
columns
)

Determines the preferred size of a text area with the specified number of rows and columns.

public Dimension

Returns:

the preferred dimensions needed for this text area
getPreferredSize
()

Overrides java.awt.Component.getPreferredSize.

Determines the preferred size of this text area.

public int

Returns:

the number of rows in the text area
getRows
()

Returns the number of rows in the text area.

public int

Returns:

an integer that indicates which scroll bars are used
getScrollbarVisibility
()

Returns an enumerated value that indicates which scroll bars the text area uses.

private static native void
initIDs()

Hides java.awt.Component.initIDs.

Initialize JNI field and method ids

public void
insert(String
the non-null text to insert
str
,
int
the position at which to insert
pos
)

Inserts the specified text at the specified position in this text area.

public synchronized void
insertText(String
the non-null text to insert
str
,
int
the position at which to insert
pos
)
Deprecated As of JDK version 1.1, replaced by insert(String, int).

Inserts the specified text at the specified position in this text area.

public Dimension

Returns:

the minimum size for the text area
minimumSize
(int
the number of rows
rows
,
int
the number of columns
columns
)
Deprecated As of JDK version 1.1, replaced by getMinimumSize(int, int).

Determines the minimum size of the text area with the specified number of rows and columns.

public Dimension
minimumSize()

Overrides java.awt.Component.minimumSize.

Deprecated As of JDK version 1.1, replaced by getMinimumSize().

Returns the minimum size of this component.

protected String

Returns:

the parameter string of this text area
paramString
()

Overrides java.awt.TextComponent.paramString.

Returns a string representing the state of this TextArea.

public Dimension

Returns:

the preferred dimensions needed for the text area
preferredSize
(int
the number of rows
rows
,
int
the number of columns
columns
)
Deprecated As of JDK version 1.1, replaced by getPreferredSize(int, int).

Determines the preferred size of the text area with the specified number of rows and columns.

public Dimension
preferredSize()

Overrides java.awt.Component.preferredSize.

Deprecated As of JDK version 1.1, replaced by getPreferredSize().

Returns the component's preferred size.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.TextComponent.readObject.

Read the ObjectInputStream.

public void
replaceRange(String
the non-null text to use as the replacement
str
,
int
the start position
start
,
int
the end position
end
)

Replaces text between the indicated start and end positions with the specified replacement text.

public synchronized void
replaceText(String
the non-null text to use as the replacement
str
,
int
the start position
start
,
int
the end position
end
)
Deprecated As of JDK version 1.1, replaced by replaceRange(String, int, int).

Replaces a range of characters between the indicated start and end positions with the specified replacement text (the text at the end position will not be replaced).

public void
setColumns(int
the number of columns
columns
)

Sets the number of columns for this text area.

public void
setRows(int
the number of rows
rows
)

Sets the number of rows for this text area.

Inherited from java.awt.TextComponent:
addTextListenerareInputMethodsEnabledenableInputMethodseventEnabledgetBackgroundgetCaretPositiongetInputMethodRequestsgetListenersgetSelectedTextgetSelectionEndgetSelectionStartgetTextgetTextListenersisEditableprocessEventprocessTextEventremoveNotifyremoveTextListenerselectselectAllsetBackgroundsetCaretPositionsetEditablesetSelectionEndsetSelectionStartsetText

Field Detail

backwardTraversalKeysback to summary
private static Set<AWTKeyStroke> backwardTraversalKeys

Cache the Sets of forward and backward traversal keys so we need not look them up each time.

baseback to summary
private static final String base
columnsback to summary
pack-priv int columns

The number of columns in the TextArea. A column is an approximate average character width that is platform-dependent. This parameter will determine the text area's width. Guaranteed to be non-negative.

See Also
setColumns(int), getColumns()
forwardTraversalKeysback to summary
private static Set<AWTKeyStroke> forwardTraversalKeys

Cache the Sets of forward and backward traversal keys so we need not look them up each time.

nameCounterback to summary
private static int nameCounter
rowsback to summary
pack-priv int rows

The number of rows in the TextArea. This parameter will determine the text area's height. Guaranteed to be non-negative.

See Also
getRows(), setRows(int)
SCROLLBARS_BOTHback to summary
public static final int SCROLLBARS_BOTH

Create and display both vertical and horizontal scrollbars.

Since
1.1
SCROLLBARS_HORIZONTAL_ONLYback to summary
public static final int SCROLLBARS_HORIZONTAL_ONLY

Create and display horizontal scrollbar only.

Since
1.1
SCROLLBARS_NONEback to summary
public static final int SCROLLBARS_NONE

Do not create or display any scrollbars for the text area.

Since
1.1
SCROLLBARS_VERTICAL_ONLYback to summary
public static final int SCROLLBARS_VERTICAL_ONLY

Create and display vertical scrollbar only.

Since
1.1
scrollbarVisibilityback to summary
private int scrollbarVisibility

Determines which scrollbars are created for the text area. It can be one of four values : SCROLLBARS_BOTH = both scrollbars.
SCROLLBARS_HORIZONTAL_ONLY = Horizontal bar only.
SCROLLBARS_VERTICAL_ONLY = Vertical bar only.
SCROLLBARS_NONE = No scrollbars.

See Also
getScrollbarVisibility()
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.TextComponent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
textAreaSerializedDataVersionback to summary
private int textAreaSerializedDataVersion

The textArea Serialized Data Version.

Constructor Detail

TextAreaback to summary
public TextArea() throws HeadlessException

Constructs a new text area with the empty string as text. This text area is created with scrollbar visibility equal to SCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless returns true
See Also
java.awt.GraphicsEnvironment#isHeadless()
TextAreaback to summary
public TextArea(String text) throws HeadlessException

Constructs a new text area with the specified text. This text area is created with scrollbar visibility equal to SCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.

Parameters
text:String

the text to be displayed; if text is null, the empty string "" will be displayed

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless returns true
See Also
java.awt.GraphicsEnvironment#isHeadless()
TextAreaback to summary
public TextArea(int rows, int columns) throws HeadlessException

Constructs a new text area with the specified number of rows and columns and the empty string as text. A column is an approximate average character width that is platform-dependent. The text area is created with scrollbar visibility equal to SCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.

Parameters
rows:int

the number of rows

columns:int

the number of columns

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless returns true
See Also
java.awt.GraphicsEnvironment#isHeadless()
TextAreaback to summary
public TextArea(String text, int rows, int columns) throws HeadlessException

Constructs a new text area with the specified text, and with the specified number of rows and columns. A column is an approximate average character width that is platform-dependent. The text area is created with scrollbar visibility equal to SCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.

Parameters
text:String

the text to be displayed; if text is null, the empty string "" will be displayed

rows:int

the number of rows

columns:int

the number of columns

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless returns true
See Also
java.awt.GraphicsEnvironment#isHeadless()
TextAreaback to summary
public TextArea(String text, int rows, int columns, int scrollbars) throws HeadlessException

Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. All TextArea constructors defer to this one.

The TextArea class defines several constants that can be supplied as values for the scrollbars argument:

  • SCROLLBARS_BOTH,
  • SCROLLBARS_VERTICAL_ONLY,
  • SCROLLBARS_HORIZONTAL_ONLY,
  • SCROLLBARS_NONE.
Any other value for the scrollbars argument is invalid and will result in this text area being created with scrollbar visibility equal to the default value of SCROLLBARS_BOTH.
Parameters
text:String

the text to be displayed; if text is null, the empty string "" will be displayed

rows:int

the number of rows; if rows is less than 0, rows is set to 0

columns:int

the number of columns; if columns is less than 0, columns is set to 0

scrollbars:int

a constant that determines what scrollbars are created to view the text area

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless returns true
Since
1.1
See Also
java.awt.GraphicsEnvironment#isHeadless()

Method Detail

addNotifyback to summary
public void addNotify()

Overrides java.awt.TextComponent.addNotify.

Creates the TextArea's peer. The peer allows us to modify the appearance of the TextArea without changing any of its functionality.

appendback to summary
public void append(String str)

Appends the given text to the text area's current text.

Note that passing null or inconsistent parameters is invalid and will result in unspecified behavior.

Parameters
str:String

the non-null text to append

Since
1.1
See Also
java.awt.TextArea#insert
appendTextback to summary
public synchronized void appendText(String str)

Deprecated

As of JDK version 1.1, replaced by append(String).

Appends the given text to the text area's current text.

Parameters
str:String

the text to append

Annotations
@Deprecated
constructComponentNameback to summary
pack-priv String constructComponentName()

Overrides java.awt.Component.constructComponentName.

Construct a name for this component. Called by getName when the name is null.

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.TextComponent.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Returns the AccessibleContext associated with this TextArea. For text areas, the AccessibleContext takes the form of an AccessibleAWTTextArea. A new AccessibleAWTTextArea instance is created if necessary.

Returns:AccessibleContext

an AccessibleAWTTextArea that serves as the AccessibleContext of this TextArea

Since
1.3
getColumnsback to summary
public int getColumns()

Returns the number of columns in this text area.

Returns:int

the number of columns in the text area

See Also
setColumns(int), getRows()
getMinimumSizeback to summary
public Dimension getMinimumSize(int rows, int columns)

Determines the minimum size of a text area with the specified number of rows and columns.

Parameters
rows:int

the number of rows

columns:int

the number of columns

Returns:Dimension

the minimum dimensions required to display the text area with the specified number of rows and columns

Since
1.1
See Also
java.awt.Component#getMinimumSize
getMinimumSizeback to summary
public Dimension getMinimumSize()

Overrides java.awt.Component.getMinimumSize.

Determines the minimum size of this text area.

Returns:Dimension

the preferred dimensions needed for this text area

Since
1.1
See Also
java.awt.Component#getPreferredSize
getPreferredSizeback to summary
public Dimension getPreferredSize(int rows, int columns)

Determines the preferred size of a text area with the specified number of rows and columns.

Parameters
rows:int

the number of rows

columns:int

the number of columns

Returns:Dimension

the preferred dimensions required to display the text area with the specified number of rows and columns

Since
1.1
See Also
java.awt.Component#getPreferredSize
getPreferredSizeback to summary
public Dimension getPreferredSize()

Overrides java.awt.Component.getPreferredSize.

Determines the preferred size of this text area.

Returns:Dimension

the preferred dimensions needed for this text area

Since
1.1
See Also
java.awt.Component#getPreferredSize
getRowsback to summary
public int getRows()

Returns the number of rows in the text area.

Returns:int

the number of rows in the text area

Since
1.0
See Also
setRows(int), getColumns()
getScrollbarVisibilityback to summary
public int getScrollbarVisibility()

Returns an enumerated value that indicates which scroll bars the text area uses.

The TextArea class defines four integer constants that are used to specify which scroll bars are available. TextArea has one constructor that gives the application discretion over scroll bars.

Returns:int

an integer that indicates which scroll bars are used

Since
1.1
See Also
java.awt.TextArea#SCROLLBARS_BOTH, java.awt.TextArea#SCROLLBARS_VERTICAL_ONLY, java.awt.TextArea#SCROLLBARS_HORIZONTAL_ONLY, java.awt.TextArea#SCROLLBARS_NONE, java.awt.TextArea#TextArea(java.lang.String, int, int, int)
initIDsback to summary
private static native void initIDs()

Hides java.awt.Component.initIDs.

Initialize JNI field and method ids

insertback to summary
public void insert(String str, int pos)

Inserts the specified text at the specified position in this text area.

Note that passing null or inconsistent parameters is invalid and will result in unspecified behavior.

Parameters
str:String

the non-null text to insert

pos:int

the position at which to insert

Since
1.1
See Also
java.awt.TextComponent#setText, java.awt.TextArea#replaceRange, java.awt.TextArea#append
insertTextback to summary
public synchronized void insertText(String str, int pos)

Deprecated

As of JDK version 1.1, replaced by insert(String, int).

Inserts the specified text at the specified position in this text area.

Parameters
str:String

the non-null text to insert

pos:int

the position at which to insert

Annotations
@Deprecated
minimumSizeback to summary
public Dimension minimumSize(int rows, int columns)

Deprecated

As of JDK version 1.1, replaced by getMinimumSize(int, int).

Determines the minimum size of the text area with the specified number of rows and columns.

Parameters
rows:int

the number of rows

columns:int

the number of columns

Returns:Dimension

the minimum size for the text area

Annotations
@Deprecated
minimumSizeback to summary
public Dimension minimumSize()

Overrides java.awt.Component.minimumSize.

Doc from java.awt.Component.minimumSize.

Deprecated

As of JDK version 1.1, replaced by getMinimumSize().

Returns the minimum size of this component.

Annotations
@Deprecated
paramStringback to summary
protected String paramString()

Overrides java.awt.TextComponent.paramString.

Returns a string representing the state of this TextArea. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:String

the parameter string of this text area

preferredSizeback to summary
public Dimension preferredSize(int rows, int columns)

Deprecated

As of JDK version 1.1, replaced by getPreferredSize(int, int).

Determines the preferred size of the text area with the specified number of rows and columns.

Parameters
rows:int

the number of rows

columns:int

the number of columns

Returns:Dimension

the preferred dimensions needed for the text area

Annotations
@Deprecated
preferredSizeback to summary
public Dimension preferredSize()

Overrides java.awt.Component.preferredSize.

Doc from java.awt.Component.preferredSize.

Deprecated

As of JDK version 1.1, replaced by getPreferredSize().

Returns the component's preferred size.

Annotations
@Deprecated
readObjectback to summary
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException

Hides java.awt.TextComponent.readObject.

Read the ObjectInputStream.

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
Exceptions
ClassNotFoundException:
if the class of a serialized object could not be found
IOException:
if an I/O error occurs
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
replaceRangeback to summary
public void replaceRange(String str, int start, int end)

Replaces text between the indicated start and end positions with the specified replacement text. The text at the end position will not be replaced. The text at the start position will be replaced (unless the start position is the same as the end position). The text position is zero-based. The inserted substring may be of a different length than the text it replaces.

Note that passing null or inconsistent parameters is invalid and will result in unspecified behavior.

Parameters
str:String

the non-null text to use as the replacement

start:int

the start position

end:int

the end position

Since
1.1
See Also
java.awt.TextArea#insert
replaceTextback to summary
public synchronized void replaceText(String str, int start, int end)

Deprecated

As of JDK version 1.1, replaced by replaceRange(String, int, int).

Replaces a range of characters between the indicated start and end positions with the specified replacement text (the text at the end position will not be replaced).

Parameters
str:String

the non-null text to use as the replacement

start:int

the start position

end:int

the end position

Annotations
@Deprecated
setColumnsback to summary
public void setColumns(int columns)

Sets the number of columns for this text area.

Parameters
columns:int

the number of columns

Exceptions
IllegalArgumentException:
if the value supplied for columns is less than 0
Since
1.1
See Also
getColumns(), setRows(int)
setRowsback to summary
public void setRows(int rows)

Sets the number of rows for this text area.

Parameters
rows:int

the number of rows

Exceptions
IllegalArgumentException:
if the value supplied for rows is less than 0
Since
1.1
See Also
getRows(), setColumns(int)
java.awt back to summary

protected Class TextArea.AccessibleAWTTextArea

extends AccessibleAWTTextComponent
Class Inheritance

This class implements accessibility support for the TextArea class. It provides an implementation of the Java Accessibility API appropriate to text area user-interface elements.
Since
1.3

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.awt.TextComponent.AccessibleAWTTextComponent.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Constructor Summary

AccessConstructor and Description
protected
AccessibleAWTTextArea()

Constructs an AccessibleAWTTextArea.

Method Summary

Modifier and TypeMethod and Description
public AccessibleStateSet

Returns:

an instance of AccessibleStateSet describing the states of the object
getAccessibleStateSet
()

Overrides java.awt.TextComponent.AccessibleAWTTextComponent.getAccessibleStateSet.

Gets the state set of this object.

Inherited from java.awt.TextComponent.AccessibleAWTTextComponent:
getAccessibleRolegetAccessibleTextgetAfterIndexgetAtIndexgetBeforeIndexgetCaretPositiongetCharacterAttributegetCharacterBoundsgetCharCountgetIndexAtPointgetSelectedTextgetSelectionEndgetSelectionStarttextValueChanged

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.TextComponent.AccessibleAWTTextComponent.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Annotations
@Serial

Constructor Detail

AccessibleAWTTextAreaback to summary
protected AccessibleAWTTextArea()

Constructs an AccessibleAWTTextArea.

Method Detail

getAccessibleStateSetback to summary
public AccessibleStateSet getAccessibleStateSet()

Overrides java.awt.TextComponent.AccessibleAWTTextComponent.getAccessibleStateSet.

Gets the state set of this object.

Returns:AccessibleStateSet

an instance of AccessibleStateSet describing the states of the object

See Also
AccessibleStateSet