ImageObserver
, MenuContainer
, Serializable
, Accessible
public non-sealed class TextArea extends TextComponent
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);
Modifier and Type | Class | Description |
---|---|---|
protected class |
TextArea.AccessibleAWTTextArea |
This class implements accessibility support for the TextArea class. |
TextComponent.AccessibleAWTTextComponent
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field | Description |
---|---|---|
static final int |
SCROLLBARS_BOTH |
Create and display both vertical and horizontal scrollbars. |
static final int |
SCROLLBARS_HORIZONTAL_ONLY |
Create and display horizontal scrollbar only. |
static final int |
SCROLLBARS_NONE |
Do not create or display any scrollbars for the text area. |
static final int |
SCROLLBARS_VERTICAL_ONLY |
Create and display vertical scrollbar only. |
textListener
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor | Description |
---|---|
TextArea() |
Constructs a new text area with the empty string as text. |
TextArea |
Constructs a new text area with the specified number of rows and columns and the empty string as text. |
TextArea |
Constructs a new text area with the specified text. |
TextArea |
Constructs a new text area with the specified text, and with the specified number of rows and columns. |
TextArea |
Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. |
Modifier and Type | Method | Description |
---|---|---|
void |
addNotify() |
Creates the TextArea 's peer. |
void |
append |
Appends the given text to the text area's current text. |
void |
appendText |
Deprecated. |
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 |
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 |
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 |
Inserts the specified text at the specified position in this text area. |
void |
insertText |
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 |
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 |
Deprecated. As of JDK version 1.1, replaced by getPreferredSize(int, int) . |
void |
replaceRange |
Replaces text between the indicated start and end positions with the specified replacement text. |
void |
replaceText |
Deprecated. As of JDK version 1.1, replaced by replaceRange(String, int, int) . |
void |
setColumns |
Sets the number of columns for this text area. |
void |
setRows |
Sets the number of rows for this text area. |
addTextListener, enableInputMethods, getBackground, getCaretPosition, getListeners, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
public static final int SCROLLBARS_BOTH
public static final int SCROLLBARS_VERTICAL_ONLY
public static final int SCROLLBARS_HORIZONTAL_ONLY
public static final int SCROLLBARS_NONE
public TextArea() throws HeadlessException
SCROLLBARS_BOTH
, so both vertical and horizontal scrollbars will be visible for this text area.HeadlessException
- if GraphicsEnvironment.isHeadless
returns truepublic TextArea(String text) throws HeadlessException
SCROLLBARS_BOTH
, so both vertical and horizontal scrollbars will be visible for this text area.text
- the text to be displayed; if text
is null
, the empty string ""
will be displayedHeadlessException
- if GraphicsEnvironment.isHeadless
returns truepublic TextArea(int rows, int columns) throws HeadlessException
SCROLLBARS_BOTH
, so both vertical and horizontal scrollbars will be visible for this text area.rows
- the number of rowscolumns
- the number of columnsHeadlessException
- if GraphicsEnvironment.isHeadless
returns truepublic TextArea(String text, int rows, int columns) throws HeadlessException
SCROLLBARS_BOTH
, so both vertical and horizontal scrollbars will be visible for this text area.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 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 truepublic 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 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 insert@Deprecated public void insertText(String str, int pos)
insert(String, int)
.str
- the non-null
text to insertpos
- the position at which to insertpublic 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 append@Deprecated public void appendText(String str)
append(String)
.str
- the text to appendpublic 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 position@Deprecated public void replaceText(String str, int start, int end)
replaceRange(String, int, int)
.str
- the non-null
text to use as the replacementstart
- the start positionend
- the end positionpublic int getRows()
public void setRows(int rows)
rows
- the number of rowsIllegalArgumentException
- if the value supplied for rows
is less than 0
public int getColumns()
public void setColumns(int columns)
columns
- the number of columnsIllegalArgumentException
- if the value supplied for columns
is less than 0
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 Dimension getPreferredSize(int rows, int columns)
rows
- the number of rowscolumns
- the number of columns@Deprecated public Dimension preferredSize(int rows, int columns)
getPreferredSize(int, int)
.rows
- the number of rowscolumns
- the number of columnspublic Dimension getPreferredSize()
getPreferredSize
in class Component
@Deprecated public Dimension preferredSize()
getPreferredSize()
.Component
preferredSize
in class Component
public Dimension getMinimumSize(int rows, int columns)
rows
- the number of rowscolumns
- the number of columns@Deprecated public Dimension minimumSize(int rows, int columns)
getMinimumSize(int, int)
.rows
- the number of rowscolumns
- the number of columnspublic Dimension getMinimumSize()
getMinimumSize
in class Component
@Deprecated public Dimension minimumSize()
getMinimumSize()
.Component
minimumSize
in class Component
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 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 interface Accessible
getAccessibleContext
in class TextComponent
AccessibleAWTTextArea
that serves as the AccessibleContext
of this TextArea
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/TextArea.html
append(String)
.