TextArea (Java 2 Platform SE 5.0) (original) (raw)
java.awt
Class TextArea
java.lang.Object
java.awt.Component
java.awt.TextComponent
java.awt.TextArea
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
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);
Since:
JDK1.0
See Also:
Nested Class Summary | |
---|---|
protected class | TextArea.AccessibleAWTTextArea 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.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 |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary |
---|
TextArea() Constructs a new text area with the empty string as text. |
[TextArea](../../java/awt/TextArea.html#TextArea%28int, int%29)(int rows, int columns) Constructs a new text area with the specified number of rows and columns and the empty string as text. |
TextArea(String text) Constructs a new text area with the specified text. |
[TextArea](../../java/awt/TextArea.html#TextArea%28java.lang.String, int, int%29)(String text, int rows, int columns) Constructs a new text area with the specified text, and with the specified number of rows and columns. |
[TextArea](../../java/awt/TextArea.html#TextArea%28java.lang.String, int, int, int%29)(String text, int rows, int columns, int scrollbars) Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. |
Method Summary | |
---|---|
void | addNotify() Creates the TextArea's peer. |
void | append(String str) Appends the given text to the text area's current text. |
void | appendText(String str) Deprecated. As of JDK version 1.1, replaced by append(String). |
AccessibleContext | getAccessibleContext() Returns the AccessibleContext associated with this TextArea. |
int | getColumns() Returns the number of columns in this text area. |
Dimension | getMinimumSize() Determines the minimum size of this text area. |
Dimension | [getMinimumSize](../../java/awt/TextArea.html#getMinimumSize%28int, int%29)(int rows, int columns) Determines the minimum size of a text area with the specified number of rows and columns. |
Dimension | getPreferredSize() Determines the preferred size of this text area. |
Dimension | [getPreferredSize](../../java/awt/TextArea.html#getPreferredSize%28int, int%29)(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 | getScrollbarVisibility() Returns an enumerated value that indicates which scroll bars the text area uses. |
void | [insert](../../java/awt/TextArea.html#insert%28java.lang.String, int%29)(String str, int pos) Inserts the specified text at the specified position in this text area. |
void | [insertText](../../java/awt/TextArea.html#insertText%28java.lang.String, int%29)(String str, int pos) Deprecated. As of JDK version 1.1, replaced by insert(String, int). |
Dimension | minimumSize() Deprecated. As of JDK version 1.1, replaced by getMinimumSize(). |
Dimension | [minimumSize](../../java/awt/TextArea.html#minimumSize%28int, int%29)(int rows, int columns) Deprecated. As of JDK version 1.1, replaced by getMinimumSize(int, int). |
protected String | paramString() Returns a string representing the state of this TextArea. |
Dimension | preferredSize() Deprecated. As of JDK version 1.1, replaced by getPreferredSize(). |
Dimension | [preferredSize](../../java/awt/TextArea.html#preferredSize%28int, int%29)(int rows, int columns) Deprecated. As of JDK version 1.1, replaced by getPreferredSize(int, int). |
void | [replaceRange](../../java/awt/TextArea.html#replaceRange%28java.lang.String, int, int%29)(String str, int start, int end) Replaces text between the indicated start and end positions with the specified replacement text. |
void | [replaceText](../../java/awt/TextArea.html#replaceText%28java.lang.String, int, int%29)(String str, int start, int end) Deprecated. As of JDK version 1.1, replaced by replaceRange(String, int, int). |
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.awt.TextComponent |
---|
addTextListener, enableInputMethods, getBackground, getCaretPosition, getInputMethodRequests, getListeners, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, [select](../../java/awt/TextComponent.html#select%28int, int%29), selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText |
Methods inherited from class java.awt.Component |
---|
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Component.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), [contains](../../java/awt/Component.html#contains%28int, int%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, int, int%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getAlignmentX, getAlignmentY, getBounds, getBounds, getColorModel, [getComponentAt](../../java/awt/Component.html#getComponentAt%28int, int%29), getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), layout, list, list, [list](../../java/awt/Component.html#list%28java.io.PrintStream, int%29), list, [list](../../java/awt/Component.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Component.html#locate%28int, int%29), location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paint, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, [repaint](../../java/awt/Component.html#repaint%28long, int, int, int, int%29), requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, [reshape](../../java/awt/Component.html#reshape%28int, int, int, int%29), resize, [resize](../../java/awt/Component.html#resize%28int, int%29), [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, [setFocusTraversalKeys](../../java/awt/Component.html#setFocusTraversalKeys%28int, java.util.Set%29), setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Field Detail |
---|
SCROLLBARS_BOTH
public static final int SCROLLBARS_BOTH
Create and display both vertical and horizontal scrollbars.
Since:
JDK1.1
See Also:
SCROLLBARS_VERTICAL_ONLY
public static final int SCROLLBARS_VERTICAL_ONLY
Create and display vertical scrollbar only.
Since:
JDK1.1
See Also:
SCROLLBARS_HORIZONTAL_ONLY
public static final int SCROLLBARS_HORIZONTAL_ONLY
Create and display horizontal scrollbar only.
Since:
JDK1.1
See Also:
SCROLLBARS_NONE
public static final int SCROLLBARS_NONE
Do not create or display any scrollbars for the text area.
Since:
JDK1.1
See Also:
Constructor Detail |
---|
TextArea
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.
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifGraphicsEnvironment.isHeadless
returns true
See Also:
GraphicsEnvironment.isHeadless()
TextArea
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
- the text to be displayed; iftext
is null
, the empty string ""
will be displayed
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifGraphicsEnvironment.isHeadless
returns true
See Also:
GraphicsEnvironment.isHeadless()
TextArea
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
- the number of rows
columns
- the number of columns
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifGraphicsEnvironment.isHeadless
returns true
See Also:
GraphicsEnvironment.isHeadless()
TextArea
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
- the text to be displayed; iftext
is null
, the empty string ""
will be displayed
rows
- the number of rows
columns
- the number of columns
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifGraphicsEnvironment.isHeadless
returns true
See Also:
GraphicsEnvironment.isHeadless()
TextArea
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 thescrollbars
argument:
SCROLLBARS_BOTH
,SCROLLBARS_VERTICAL_ONLY
,SCROLLBARS_HORIZONTAL_ONLY
,SCROLLBARS_NONE
. Any other value for thescrollbars
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
- the text to be displayed; iftext
is null
, the empty string ""
will be displayed
rows
- the number of rows; ifrows
is less than 0
,rows
is set to 0
columns
- the number of columns; ifcolumns
is less than 0
,columns
is set to 0
scrollbars
- a constant that determines what scrollbars are created to view the text area
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifGraphicsEnvironment.isHeadless
returns true
Since:
JDK1.1
See Also:
GraphicsEnvironment.isHeadless()
Method Detail |
---|
addNotify
public void addNotify()
Creates the TextArea
's peer. The peer allows us to modify the appearance of the TextArea
without changing any of its functionality.
Overrides:
[addNotify](../../java/awt/TextComponent.html#addNotify%28%29)
in class [TextComponent](../../java/awt/TextComponent.html "class in java.awt")
See Also:
insert
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
- the non-null
text to insert
pos
- the position at which to insert
Since:
JDK1.1
See Also:
TextComponent.setText(java.lang.String), [replaceRange(java.lang.String, int, int)](../../java/awt/TextArea.html#replaceRange%28java.lang.String, int, int%29), append(java.lang.String)
insertText
@Deprecated public void insertText(String str, int pos)
Deprecated. As of JDK version 1.1, replaced by insert(String, int)
.
append
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
- the non-null
text to append
Since:
JDK1.1
See Also:
[insert(java.lang.String, int)](../../java/awt/TextArea.html#insert%28java.lang.String, int%29)
appendText
@Deprecated public void appendText(String str)
Deprecated. As of JDK version 1.1, replaced by append(String)
.
replaceRange
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
- the non-null
text to use as the replacement
start
- the start position
end
- the end position
Since:
JDK1.1
See Also:
[insert(java.lang.String, int)](../../java/awt/TextArea.html#insert%28java.lang.String, int%29)
replaceText
@Deprecated public void replaceText(String str, int start, int end)
Deprecated. As of JDK version 1.1, replaced by replaceRange(String, int, int)
.
getRows
public int getRows()
Returns the number of rows in the text area.
Returns:
the number of rows in the text area
Since:
JDK1
See Also:
setRows
public void setRows(int rows)
Sets the number of rows for this text area.
Parameters:
rows
- the number of rows
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the value supplied for rows
is less than 0
Since:
JDK1.1
See Also:
getColumns
public int getColumns()
Returns the number of columns in this text area.
Returns:
the number of columns in the text area
See Also:
setColumns
public void setColumns(int columns)
Sets the number of columns for this text area.
Parameters:
columns
- the number of columns
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the value supplied for columns
is less than 0
Since:
JDK1.1
See Also:
getScrollbarVisibility
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:
an integer that indicates which scroll bars are used
Since:
JDK1.1
See Also:
SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE, [TextArea(java.lang.String, int, int, int)](../../java/awt/TextArea.html#TextArea%28java.lang.String, int, int, int%29)
getPreferredSize
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
- the number of rows
columns
- the number of columns
Returns:
the preferred dimensions required to display the text area with the specified number of rows and columns
Since:
JDK1.1
See Also:
preferredSize
@Deprecated public Dimension preferredSize(int rows, int columns)
Deprecated. As of JDK version 1.1, replaced by getPreferredSize(int, int)
.
getPreferredSize
public Dimension getPreferredSize()
Determines the preferred size of this text area.
Overrides:
[getPreferredSize](../../java/awt/Component.html#getPreferredSize%28%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
Returns:
the preferred dimensions needed for this text area
Since:
JDK1.1
See Also:
preferredSize
@Deprecated public Dimension preferredSize()
Deprecated. As of JDK version 1.1, replaced by getPreferredSize()
.
Overrides:
[preferredSize](../../java/awt/Component.html#preferredSize%28%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
getMinimumSize
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
- the number of rows
columns
- the number of columns
Returns:
the minimum dimensions required to display the text area with the specified number of rows and columns
Since:
JDK1.1
See Also:
minimumSize
@Deprecated public Dimension minimumSize(int rows, int columns)
Deprecated. As of JDK version 1.1, replaced by getMinimumSize(int, int)
.
getMinimumSize
public Dimension getMinimumSize()
Determines the minimum size of this text area.
Overrides:
[getMinimumSize](../../java/awt/Component.html#getMinimumSize%28%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
Returns:
the preferred dimensions needed for this text area
Since:
JDK1.1
See Also:
minimumSize
@Deprecated public Dimension minimumSize()
Deprecated. As of JDK version 1.1, replaced by getMinimumSize()
.
Overrides:
[minimumSize](../../java/awt/Component.html#minimumSize%28%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
paramString
protected String 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
.
Overrides:
[paramString](../../java/awt/TextComponent.html#paramString%28%29)
in class [TextComponent](../../java/awt/TextComponent.html "class in java.awt")
Returns:
the parameter string of this text area
getAccessibleContext
public AccessibleContext getAccessibleContext()
Returns the AccessibleContext
associated with this TextArea
. For text areas, theAccessibleContext
takes the form of an AccessibleAWTTextArea
. A new AccessibleAWTTextArea
instance is created if necessary.
Specified by:
[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29)
in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")
Overrides:
[getAccessibleContext](../../java/awt/TextComponent.html#getAccessibleContext%28%29)
in class [TextComponent](../../java/awt/TextComponent.html "class in java.awt")
Returns:
an AccessibleAWTTextArea
that serves as the AccessibleContext
of this TextArea
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.