| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public class TextArea extends TextComponent
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:
This text area could be created by the following line of code:
new TextArea("Hello", 5, 40);
Nested Class Summary | |
---|---|
protected class |
This class implements accessibility support for the TextArea class. |
Nested classes/interfaces inherited from class java.awt.TextComponent |
---|
TextComponent.AccessibleAWTTextComponent |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
SCROLLBARS_BOTH
Create and display both vertical and horizontal scrollbars. |
static int |
SCROLLBARS_HORIZONTAL_ONLY
Create and display horizontal scrollbar only. |
static int |
SCROLLBARS_NONE
Do not create or display any scrollbars for the text area. |
static int |
SCROLLBARS_VERTICAL_ONLY
Create and display vertical scrollbar only. |
Fields inherited from class java.awt.TextComponent |
---|
textListener |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
---|---|
TextArea() Constructs a new text area with the empty string as text. |
|
TextArea(int rows, int columns) Constructs a new text area with the specified number of rows and columns and the empty string as text. |
|
Constructs a new text area with the specified text. |
|
Constructs a new text area with the specified text, and with the specified number of rows and columns. |
|
Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. |
Method Summary | |
---|---|
void |
Creates the TextArea 's peer.
|
void |
Appends the given text to the text area's current text. |
void |
appendText(String str) |
AccessibleContext |
Returns the AccessibleContext associated with
this TextArea .
|
int |
Returns the number of columns in this text area. |
Dimension |
Determines the minimum size of this text area. |
Dimension |
getMinimumSize(int rows, int columns) Determines the minimum size of a text area with the specified number of rows and columns. |
Dimension |
Determines the preferred size of this text area. |
Dimension |
getPreferredSize(int rows, int columns) Determines the preferred size of a text area with the specified number of rows and columns. |
int |
getRows() Returns the number of rows in the text area. |
int |
Returns an enumerated value that indicates which scroll bars the text area uses. |
void |
Inserts the specified text at the specified position in this text area. |
void |
insertText(String str, int pos) |
Dimension |
|
Dimension |
minimumSize(int rows, int columns) |
protected String |
Returns a string representing the state of this TextArea .
|
Dimension |
|
Dimension |
preferredSize(int rows, int columns) |
void |
replaceRange(String str, int start, int end) Replaces text between the indicated start and end positions with the specified replacement text. |
void |
replaceText(String str, int start, int end) |
void |
setColumns(int columns) Sets the number of columns for this text area. |
void |
setRows(int rows) Sets the number of rows for this text area. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SCROLLBARS_BOTH
public static final int SCROLLBARS_HORIZONTAL_ONLY
public static final int SCROLLBARS_NONE
public static final int SCROLLBARS_VERTICAL_ONLY
Constructor Detail |
---|
public TextArea() throws HeadlessException
HeadlessException
- if
GraphicsEnvironment.isHeadless
returns truepublic TextArea(int rows, int columns) throws HeadlessException
rows
- the number of rowscolumns
- the number of columnsHeadlessException
- if
GraphicsEnvironment.isHeadless
returns truepublic TextArea(String text) throws HeadlessException
text
- the text to be displayed; if
text
is null
, the empty
string ""
will be displayedHeadlessException
- if
GraphicsEnvironment.isHeadless
returns truepublic TextArea(String text, int rows, int columns) throws HeadlessException
text
- the text to be displayed; if
text
is null
, the empty
string ""
will be displayedrows
- the number of rowscolumns
- the number of columnsHeadlessException
- if
GraphicsEnvironment.isHeadless
returns truepublic TextArea(String text, int rows, int columns, int scrollbars) throws HeadlessException
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
.
scrollbars
argument is invalid and will result in
this text area being created with scrollbar visibility equal to
the default value of {@link #SCROLLBARS_BOTH}.
text
- the text to be displayed; if
text
is null
, the empty
string ""
will be displayedrows
- the number of rows; if
rows
is less than 0
,
rows
is set to 0
columns
- the number of columns; if
columns
is less than 0
,
columns
is set to 0
scrollbars
- a constant that determines what
scrollbars are created to view the text areaHeadlessException
- if
GraphicsEnvironment.isHeadless
returns trueMethod Detail |
---|
public void addNotify()
TextArea
's peer. The peer allows us to modify
the appearance of the TextArea
without changing any of its
functionality.
addNotify
in class TextComponent
public void append(String str)
Note that passing null
or inconsistent
parameters is invalid and will result in unspecified
behavior.
str
- the non-null
text to appendpublic synchronized void appendText(String str)
str
public AccessibleContext getAccessibleContext()
AccessibleContext
associated with
this TextArea
. For text areas, the
AccessibleContext
takes the form of an
AccessibleAWTTextArea
.
A new AccessibleAWTTextArea
instance is created if necessary.
getAccessibleContext
in class TextComponent
AccessibleAWTTextArea
that serves as the
AccessibleContext
of this TextArea
public int getColumns()
public Dimension getMinimumSize()
getMinimumSize
in class Component
public Dimension getMinimumSize(int rows, int columns)
rows
- the number of rowscolumns
- the number of columnspublic Dimension getPreferredSize()
getPreferredSize
in class Component
public Dimension getPreferredSize(int rows, int columns)
rows
- the number of rowscolumns
- the number of columnspublic int getRows()
public int getScrollbarVisibility()
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.
public void insert(String str, int pos)
Note that passing null
or inconsistent
parameters is invalid and will result in unspecified
behavior.
str
- the non-null
text to insertpos
- the position at which to insertpublic synchronized void insertText(String str, int pos)
str
pos
public Dimension minimumSize()
minimumSize
in class Component
public Dimension minimumSize(int rows, int columns)
rows
columns
protected String paramString()
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
.
paramString
in class TextComponent
public Dimension preferredSize()
preferredSize
in class Component
public Dimension preferredSize(int rows, int columns)
rows
columns
public void replaceRange(String str, int start, int end)
Note that passing null
or inconsistent
parameters is invalid and will result in unspecified
behavior.
str
- the non-null
text to use as
the replacementstart
- the start positionend
- the end positionpublic synchronized void replaceText(String str, int start, int end)
str
start
end
public void setColumns(int columns)
columns
- the number of columnspublic void setRows(int rows)
rows
- the number of rows
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |