|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.text.JTextComponent
![]()
![]()
![]()
javax.swing.JTextArea
, MenuContainer
, Serializable
, Accessible
, Scrollable

public class JTextArea

A JTextArea is a multi-line area that displays plain text.
It is intended to be a lightweight component that provides source
compatibility with the java.awt.TextArea class where it can
reasonably do so.
You can find information and examples of using all the text components in
Using Text Components,
a section in The Java Tutorial.
This component has capabilities not found in the
java.awt.TextArea class. The superclass should be
consulted for additional capabilities.
Alternative multi-line text classes with
more capabilities are JTextPane and JEditorPane.
The java.awt.TextArea internally handles scrolling.
JTextArea is different in that it doesn't manage scrolling,
but implements the swing Scrollable interface. This allows it
to be placed inside a JScrollPane if scrolling
behavior is desired, and used directly if scrolling is not desired.
The java.awt.TextArea has the ability to do line wrapping.
This was controlled by the horizontal scrolling policy. Since
scrolling is not done by JTextArea directly, backward
compatibility must be provided another way. JTextArea has
a bound property for line wrapping that controls whether or
not it will wrap lines. By default, the line wrapping property
is set to false (not wrapped).
java.awt.TextArea has two properties rows
and columns that are used to determine the preferred size.
JTextArea uses these properties to indicate the
preferred size of the viewport when placed inside a JScrollPane
to match the functionality provided by java.awt.TextArea.
JTextArea has a preferred size of what is needed to
display all of the text, so that it functions properly inside of
a JScrollPane. If the value for rows
or columns is equal to zero,
the preferred size along that axis is used for
the viewport preferred size along the same axis.
The java.awt.TextArea could be monitored for changes by adding
a TextListener for TextEvents.
In the JTextComponent based
components, changes are broadcasted from the model via a
DocumentEvent to DocumentListeners.
The DocumentEvent gives
the location of the change and the kind of change if desired.
The code fragment might look something like:
DocumentListener myListener = ??;
JTextArea myArea = ??;
myArea.getDocument().addDocumentListener(myListener);
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder
.
JTextPane
,
JEditorPane
,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
JTextArea.AccessibleJTextArea
This class implements accessibility support for the JTextArea class. |
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent ![]() |
|---|
JTextComponent.AccessibleJTextComponent |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary |
|---|
Fields inherited from class javax.swing.text.JTextComponent ![]() |
|---|
DEFAULT_KEYMAP |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JTextArea
Constructs a new TextArea. |
|
JTextArea
Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0). |
|
JTextArea
Constructs a new JTextArea with the specified number of rows and columns, and the given model. |
|
JTextArea
Constructs a new empty TextArea with the specified number of rows and columns. |
|
JTextArea
Constructs a new TextArea with the specified text displayed. |
|
JTextArea
Constructs a new TextArea with the specified text and number of rows and columns. |
|
| Method Summary | |
|---|---|
void |
append
Appends the given text to the end of the document. |
protected Document |
createDefaultModel
Creates the default implementation of the model to be used at construction if one isn't explicitly given. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated with this JTextArea. |
int |
getColumns
Returns the number of columns in the TextArea. |
protected int |
getColumnWidth
Gets column width. |
int |
getLineCount
Determines the number of lines contained in the area. |
int |
getLineEndOffset
Determines the offset of the end of the given line. |
int |
getLineOfOffset
Translates an offset into the components text to a line number. |
int |
getLineStartOffset
Determines the offset of the start of the given line. |
boolean |
getLineWrap
Gets the line-wrapping policy of the text area. |
Dimension |
getPreferredScrollableViewportSize
Returns the preferred size of the viewport if this component is embedded in a JScrollPane. |
Dimension |
getPreferredSize
Returns the preferred size of the TextArea. |
protected int |
getRowHeight
Defines the meaning of the height of a row. |
int |
getRows
Returns the number of rows in the TextArea. |
boolean |
getScrollableTracksViewportWidth
Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport. |
int |
getScrollableUnitIncrement
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. |
int |
getTabSize
Gets the number of characters used to expand tabs. |
String |
getUIClassID
Returns the class ID for the UI. |
boolean |
getWrapStyleWord
Gets the style of wrapping used if the text area is wrapping lines. |
void |
insert
Inserts the specified text at the specified position. |
protected String |
paramString
Returns a string representation of this JTextArea. |
void |
replaceRange
Replaces text from the indicated start to end position with the new text specified. |
void |
setColumns
Sets the number of columns for this TextArea. |
void |
setFont
Sets the current font. |
void |
setLineWrap
Sets the line-wrapping policy of the text area. |
void |
setRows
Sets the number of rows for this TextArea. |
void |
setTabSize
Sets the number of characters to expand tabs to. |
void |
setWrapStyleWord
Sets the style of wrapping used if the text area is wrapping lines. |
Methods inherited from class javax.swing.text.JTextComponent ![]() |
|---|
addCaretListener |