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 TextEvent
s.
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);
For the keyboard keys used by this component in the standard Look and
Feel (L&F) renditions, see the
JTextArea
key assignments.
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 {@link java.beans.XMLEncoder}.
Attribute Summary | ||
---|---|---|
Attribute | Type | Description |
actionmap | ActionMap | Sets the ActionMap to am . |
alignmentx | <float> | Sets the the vertical alignment. |
alignmenty | <float> | Sets the the horizontal alignment. |
autoscrolls | <boolean> | Sets the autoscrolls property.
|
background | <color> | Sets the background color of this component. |
border | Border | Sets the border of this component. |
bounds | <rectangle> | Moves and resizes this component to conform to the new
bounding rectangle r . |
caret | Caret | Sets the caret to be used. |
caretcolor | <color> | Sets the current color used to render the caret. |
caretposition | <int> | Sets the position of the text insertion caret for the
TextComponent . |
columns | <int> | Sets the number of columns for this TextArea. |
componentorientation | ComponentOrientation | |
cursor | <cursor> | Sets the cursor image to the specified cursor. |
debuggraphicsoptions | <int> | Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. |
defaultlocale | <locale> | Sets the default locale used to initialize each JComponent's locale property upon creation. |
disabledtextcolor | <color> | Sets the current color used to render the disabled text. |
document | Document | Associates the editor with a text document. |
doublebuffered | <boolean> | Sets whether the this component should use a buffer to paint. |
dragenabled | <boolean> | Sets the dragEnabled property,
which must be true to enable
automatic drag handling (the first part of drag and drop)
on this component.
|
droptarget | DropTarget | Associate a DropTarget with this component.
|
editable | <boolean> | Sets the specified boolean to indicate whether or not this
TextComponent should be editable.
|
enabled | <boolean> | Sets whether or not this component is enabled. |
focusable | <boolean> | Sets the focusable state of this Component to the specified value. |
focusaccelerator | <char> | Sets the key accelerator that will cause the receiving text component to get the focus. |
focuscycleroot | <boolean> | Sets whether this Container is the root of a focus traversal cycle. |
focustraversalkeysenabled | <boolean> | Sets whether focus traversal keys are enabled for this Component. |
focustraversalpolicy | FocusTraversalPolicy | Sets the focus traversal policy that will manage keyboard traversal of this Container's children, if this Container is a focus cycle root. |
font | <font> | Sets the current font. |
foreground | <color> | Sets the foreground color of this component. |
highlighter | Highlighter | Sets the highlighter to be used. |
ignorerepaint | <boolean> | Sets whether or not paint messages received from the operating system should be ignored. |
inputverifier | InputVerifier | Sets the input verifier for this component. |
keymap | Keymap | Sets the keymap to use for binding events to actions. |
layout | LayoutManager | Sets the layout manager for this container. |
linewrap | <boolean> | Sets the line-wrapping policy of the text area. |
locale | <locale> | Sets the locale of this component. |
location | <point> | Moves this component to a new location. |
margin | <insets> | Sets margin space between the text component's border and its text. |
maximumsize | <dimension> | Sets the maximum size of this component to a constant value. |
minimumsize | <dimension> | Sets the minimum size of this component to a constant value. |
name | <text> | Sets the name of the component to the specified string. |
navigationfilter | NavigationFilter | Sets the NavigationFilter . |
nextfocusablecomponent | Component | Overrides the default FocusTraversalPolicy for this
JComponent 's focus traversal cycle by unconditionally
setting the specified Component as the next
Component in the cycle, and this JComponent
as the specified Component 's previous
Component in the cycle. |
opaque | <boolean> | If true the component paints every pixel within its bounds. |
preferredsize | <dimension> | Sets the preferred size of this component. |
requestfocusenabled | <boolean> | Provides a hint as to whether or not this JComponent
should get focus. |
rows | <int> | Sets the number of rows for this TextArea. |
selectedtextcolor | <color> | Sets the current color used to render the selected text. |
selectioncolor | <color> | Sets the current color used to render the selection. |
selectionend | <int> | Sets the selection end to the specified position. |
selectionstart | <int> | Sets the selection start to the specified position. |
size | <dimension> | Resizes this component so that it has width d.width
and height d.height . |
tabsize | <int> | Sets the number of characters to expand tabs to. |
text | <text> | Sets the text of this TextComponent
to the specified text. |
tooltiptext | <text> | Registers the text to display in a tool tip. |
transferhandler | TransferHandler | Sets the transferHandler property,
which is null if the component does
not support data transfer operations.
|
ui | TextUI | Sets the user-interface factory for this text-oriented editor. |
verifyinputwhenfocustarget | <boolean> | Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. |
visible | <boolean> | Makes the component visible or invisible. |
wrapstyleword | <boolean> | Sets the style of wrapping used if the text area is wrapping lines. |