javax.swing
public class JTextArea extends JTextComponent
JTextArea
component provides a multi-line area for displaying
and editing plain text. The component is designed to act as a lightweight
replacement for the heavyweight java.awt.TextArea
component,
which provides similar functionality using native widgets.
This component has additional functionality to the AWT class. It follows
the same design pattern as seen in other text components, such as
JTextField
, JTextPane
and JEditorPane
,
and embodied in JTextComponent
. These classes separate the text
(the model) from its appearance within the onscreen component (the view). The
text is held within a javax.swing.text.Document
object, which can
also maintain relevant style information where necessary. As a result, it is the
document that should be monitored for textual changes, via
DocumentEvent
s delivered to registered
DocumentListener
s, rather than this component.
Unlike java.awt.TextArea
, JTextArea
does not
handle scrolling. Instead, this functionality is delegated to a
JScrollPane
, which can contain the text area and handle
scrolling when required. Likewise, the word wrapping functionality
of the AWT component is converted to a property of this component
and the rows
and columns
properties
are used in calculating the preferred size of the scroll pane's
view port.
See Also: TextArea JTextComponent JTextField JTextPane JEditorPane Document DocumentEvent DocumentListener
Nested Class Summary | |
---|---|
protected class | JTextArea.AccessibleJTextArea
Provides accessibility support for JTextArea .
|
Constructor Summary | |
---|---|
JTextArea()
Creates a new JTextArea object. | |
JTextArea(String text)
Creates a new JTextArea object.
| |
JTextArea(int rows, int columns)
Creates a new JTextArea object.
| |
JTextArea(String text, int rows, int columns)
Creates a new JTextArea object.
| |
JTextArea(Document doc)
Creates a new JTextArea object.
| |
JTextArea(Document doc, String text, int rows, int columns)
Creates a new JTextArea object.
|
Method Summary | |
---|---|
void | append(String toAppend)
Appends the supplied text to the current contents
of the document model.
|
protected Document | createDefaultModel()
Creates the default document model.
|
AccessibleContext | getAccessibleContext()
Returns the accessible context associated with the JTextArea .
|
int | getColumns()
Returns the current number of columns.
|
protected int | getColumnWidth() |
int | getLineCount() |
int | getLineEndOffset(int line) |
int | getLineOfOffset(int offset) |
int | getLineStartOffset(int line) |
boolean | getLineWrap()
Checks whether line wrapping is enabled.
|
Dimension | getPreferredScrollableViewportSize()
Returns the preferred size of that text component in the case
it is embedded within a JScrollPane. |
Dimension | getPreferredSize()
Returns the preferred size for the JTextArea. |
protected int | getRowHeight() |
int | getRows()
Returns the current number of rows.
|
boolean | getScrollableTracksViewportWidth()
Returns true if the width of this component should be forced
to match the width of a surrounding view port. |
int | getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Returns the increment that is needed to expose exactly one new line
of text. |
int | getTabSize()
Returns the number of characters used for a tab.
|
String | getUIClassID()
Returns the UI class ID string.
|
boolean | getWrapStyleWord()
Checks whether word style wrapping is enabled.
|
void | insert(String string, int position)
Inserts the supplied text at the specified position. |
void | replaceRange(String text, int start, int end) |
void | setColumns(int columns)
Sets the number of rows.
|
void | setLineWrap(boolean flag)
Enables/disables line wrapping.
|
void | setRows(int rows)
Sets the number of rows.
|
void | setTabSize(int newSize)
Sets the number of characters used for a tab to the
supplied value. |
void | setWrapStyleWord(boolean flag)
Enables/Disables word style wrapping.
|
JTextArea
object.JTextArea
object.
Parameters: text the initial text
JTextArea
object.
Parameters: rows the number of rows columns the number of cols
Throws: IllegalArgumentException if rows or columns are negative
JTextArea
object.
Parameters: text the initial text rows the number of rows columns the number of cols
Throws: IllegalArgumentException if rows or columns are negative
JTextArea
object.
Parameters: doc the document model to use
JTextArea
object.
Parameters: doc the document model to use text the initial text rows the number of rows columns the number of cols
Throws: IllegalArgumentException if rows or columns are negative
Parameters: toAppend the text to append
Returns: a new default model
JTextArea
.
Returns: the accessible context associated with the JTextArea
Returns: number of columns
Returns: true
if line wrapping is enabled,
false
otherwise
Returns: the preferred size of that text component in the case it is embedded within a JScrollPane
Returns: the preferred size of the JTextArea
Returns: number of rows
Returns: true if lines are wrapped.
direction
.
Parameters: visibleRect the view area that is visible in the viewport orientation either {@link SwingConstants#VERTICAL} or {@link SwingConstants#HORIZONTAL} direction less than zero for up/left scrolling, greater than zero for down/right scrolling
Returns: the increment that is needed to expose exactly one new row or column of text
Throws: IllegalArgumentException if orientation
is invalid
Returns: the current number of spaces used for a tab.
Returns: the string "TextAreaUI"
Returns: true
if word style wrapping is enabled,
false
otherwise
Parameters: string The string of text to insert. position The position at which to insert the supplied text.
Throws: IllegalArgumentException if the position is < 0 or greater than the length of the current text.
Parameters: columns number of columns
Throws: IllegalArgumentException if columns is negative
Parameters: flag true
to enable line wrapping,
false
otherwise
Parameters: rows number of rows
Throws: IllegalArgumentException if rows is negative
Parameters: newSize The new number of characters to use for a tab.
Parameters: flag true
to enable word style wrapping,
false
otherwise