Class TextArea
java.lang.Object
java.awt.Component
java.awt.TextComponent
java.awt.TextArea
- All Implemented Interfaces:
- ImageObserver,- MenuContainer,- Serializable,- Accessible
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:
- 1.0
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theTextAreaclass.Nested classes/interfaces declared in class java.awt.TextComponentTextComponent.AccessibleAWTTextComponentNested classes/interfaces declared in class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intCreate and display both vertical and horizontal scrollbars.static final intCreate and display horizontal scrollbar only.static final intDo not create or display any scrollbars for the text area.static final intCreate and display vertical scrollbar only.Fields declared in class java.awt.TextComponenttextListenerFields declared in class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
- 
Constructor SummaryConstructorsConstructorDescriptionTextArea()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 SummaryModifier and TypeMethodDescriptionvoidCreates theTextArea's peer.voidAppends the given text to the text area's current text.voidappendText(String str) Deprecated.Returns theAccessibleContextassociated with thisTextArea.intReturns the number of columns in this text area.Determines the minimum size of this text area.getMinimumSize(int rows, int columns) Determines the minimum size of a text area with the specified number of rows and columns.Determines the preferred size of this text area.getPreferredSize(int rows, int columns) Determines the preferred size of a text area with the specified number of rows and columns.intgetRows()Returns the number of rows in the text area.intReturns an enumerated value that indicates which scroll bars the text area uses.voidInserts the specified text at the specified position in this text area.voidinsertText(String str, int pos) Deprecated.As of JDK version 1.1, replaced byinsert(String, int).Deprecated.As of JDK version 1.1, replaced bygetMinimumSize().minimumSize(int rows, int columns) Deprecated.As of JDK version 1.1, replaced bygetMinimumSize(int, int).protected StringReturns a string representing the state of thisTextArea.Deprecated.As of JDK version 1.1, replaced bygetPreferredSize().preferredSize(int rows, int columns) Deprecated.As of JDK version 1.1, replaced bygetPreferredSize(int, int).voidreplaceRange(String str, int start, int end) Replaces text between the indicated start and end positions with the specified replacement text.voidreplaceText(String str, int start, int end) Deprecated.As of JDK version 1.1, replaced byreplaceRange(String, int, int).voidsetColumns(int columns) Sets the number of columns for this text area.voidsetRows(int rows) Sets the number of rows for this text area.Methods declared in class java.awt.TextComponentaddTextListener, enableInputMethods, getBackground, getCaretPosition, getListeners, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setTextMethods declared in class java.awt.Componentaction, 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
- 
Field Details- 
SCROLLBARS_BOTHpublic static final int SCROLLBARS_BOTHCreate and display both vertical and horizontal scrollbars.- Since:
- 1.1
- See Also:
 
- 
SCROLLBARS_VERTICAL_ONLYpublic static final int SCROLLBARS_VERTICAL_ONLYCreate and display vertical scrollbar only.- Since:
- 1.1
- See Also:
 
- 
SCROLLBARS_HORIZONTAL_ONLYpublic static final int SCROLLBARS_HORIZONTAL_ONLYCreate and display horizontal scrollbar only.- Since:
- 1.1
- See Also:
 
- 
SCROLLBARS_NONEpublic static final int SCROLLBARS_NONEDo not create or display any scrollbars for the text area.- Since:
- 1.1
- See Also:
 
 
- 
- 
Constructor Details- 
TextAreaConstructs a new text area with the empty string as text. This text area is created with scrollbar visibility equal toSCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.- Throws:
- HeadlessException- if- GraphicsEnvironment.isHeadlessreturns true
- See Also:
 
- 
TextAreaConstructs a new text area with the specified text. This text area is created with scrollbar visibility equal toSCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.- Parameters:
- text- the text to be displayed; if- textis- null, the empty string- ""will be displayed
- Throws:
- HeadlessException- if- GraphicsEnvironment.isHeadlessreturns true
- See Also:
 
- 
TextAreaConstructs 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 toSCROLLBARS_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- if- GraphicsEnvironment.isHeadlessreturns true
- See Also:
 
- 
TextAreaConstructs 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 toSCROLLBARS_BOTH, so both vertical and horizontal scrollbars will be visible for this text area.- Parameters:
- text- the text to be displayed; if- textis- null, the empty string- ""will be displayed
- rows- the number of rows
- columns- the number of columns
- Throws:
- HeadlessException- if- GraphicsEnvironment.isHeadlessreturns true
- See Also:
 
- 
TextAreaConstructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. AllTextAreaconstructors defer to this one.The TextAreaclass defines several constants that can be supplied as values for thescrollbarsargument:- SCROLLBARS_BOTH,
- SCROLLBARS_VERTICAL_ONLY,
- SCROLLBARS_HORIZONTAL_ONLY,
- SCROLLBARS_NONE.
 scrollbarsargument is invalid and will result in this text area being created with scrollbar visibility equal to the default value ofSCROLLBARS_BOTH.- Parameters:
- text- the text to be displayed; if- textis- null, the empty string- ""will be displayed
- rows- the number of rows; if- rowsis less than- 0,- rowsis set to- 0
- columns- the number of columns; if- columnsis less than- 0,- columnsis set to- 0
- scrollbars- a constant that determines what scrollbars are created to view the text area
- Throws:
- HeadlessException- if- GraphicsEnvironment.isHeadlessreturns true
- Since:
- 1.1
- See Also:
 
 
- 
- 
Method Details- 
addNotifypublic void addNotify()Creates theTextArea's peer. The peer allows us to modify the appearance of theTextAreawithout changing any of its functionality.- Overrides:
- addNotifyin class- TextComponent
- See Also:
 
- 
insertInserts the specified text at the specified position in this text area.Note that passing nullor inconsistent parameters is invalid and will result in unspecified behavior.- Parameters:
- str- the non-- nulltext to insert
- pos- the position at which to insert
- Since:
- 1.1
- See Also:
 
- 
insertTextDeprecated.As of JDK version 1.1, replaced byinsert(String, int).Inserts the specified text at the specified position in this text area.- Parameters:
- str- the non-- nulltext to insert
- pos- the position at which to insert
 
- 
appendAppends the given text to the text area's current text.Note that passing nullor inconsistent parameters is invalid and will result in unspecified behavior.- Parameters:
- str- the non-- nulltext to append
- Since:
- 1.1
- See Also:
 
- 
appendTextDeprecated.As of JDK version 1.1, replaced byappend(String).Appends the given text to the text area's current text.- Parameters:
- str- the text to append
 
- 
replaceRangeReplaces 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 nullor inconsistent parameters is invalid and will result in unspecified behavior.- Parameters:
- str- the non-- nulltext to use as the replacement
- start- the start position
- end- the end position
- Since:
- 1.1
- See Also:
 
- 
replaceTextDeprecated.As of JDK version 1.1, replaced byreplaceRange(String, int, int).Replaces a range of characters between the indicated start and end positions with the specified replacement text (the text at the end position will not be replaced).- Parameters:
- str- the non-- nulltext to use as the replacement
- start- the start position
- end- the end position
 
- 
getRowspublic int getRows()Returns the number of rows in the text area.- Returns:
- the number of rows in the text area
- Since:
- 1.0
- See Also:
 
- 
setRowspublic void setRows(int rows) Sets the number of rows for this text area.- Parameters:
- rows- the number of rows
- Throws:
- IllegalArgumentException- if the value supplied for- rowsis less than- 0
- Since:
- 1.1
- See Also:
 
- 
getColumnspublic int getColumns()Returns the number of columns in this text area.- Returns:
- the number of columns in the text area
- See Also:
 
- 
setColumnspublic void setColumns(int columns) Sets the number of columns for this text area.- Parameters:
- columns- the number of columns
- Throws:
- IllegalArgumentException- if the value supplied for- columnsis less than- 0
- Since:
- 1.1
- See Also:
 
- 
getScrollbarVisibilitypublic int getScrollbarVisibility()Returns an enumerated value that indicates which scroll bars the text area uses.The TextAreaclass defines four integer constants that are used to specify which scroll bars are available.TextAreahas one constructor that gives the application discretion over scroll bars.- Returns:
- an integer that indicates which scroll bars are used
- Since:
- 1.1
- See Also:
 
- 
getPreferredSizeDetermines 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:
- 1.1
- See Also:
 
- 
preferredSizeDeprecated.As of JDK version 1.1, replaced bygetPreferredSize(int, int).Determines the preferred size of the 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 needed for the text area
 
- 
getPreferredSizeDetermines the preferred size of this text area.- Overrides:
- getPreferredSizein class- Component
- Returns:
- the preferred dimensions needed for this text area
- Since:
- 1.1
- See Also:
 
- 
preferredSizeDeprecated.As of JDK version 1.1, replaced bygetPreferredSize().Description copied from class:ComponentReturns the component's preferred size.- Overrides:
- preferredSizein class- Component
- Returns:
- the component's preferred size
 
- 
getMinimumSizeDetermines 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:
- 1.1
- See Also:
 
- 
minimumSizeDeprecated.As of JDK version 1.1, replaced bygetMinimumSize(int, int).Determines the minimum size of the text area with the specified number of rows and columns.- Parameters:
- rows- the number of rows
- columns- the number of columns
- Returns:
- the minimum size for the text area
 
- 
getMinimumSizeDetermines the minimum size of this text area.- Overrides:
- getMinimumSizein class- Component
- Returns:
- the preferred dimensions needed for this text area
- Since:
- 1.1
- See Also:
 
- 
minimumSizeDeprecated.As of JDK version 1.1, replaced bygetMinimumSize().Description copied from class:ComponentReturns the minimum size of this component.- Overrides:
- minimumSizein class- Component
- Returns:
- the minimum size of this component
 
- 
paramStringReturns a string representing the state of thisTextArea. 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 benull.- Overrides:
- paramStringin class- TextComponent
- Returns:
- the parameter string of this text area
 
- 
getAccessibleContextReturns theAccessibleContextassociated with thisTextArea. For text areas, theAccessibleContexttakes the form of anAccessibleAWTTextArea. A newAccessibleAWTTextAreainstance is created if necessary.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- TextComponent
- Returns:
- an AccessibleAWTTextAreathat serves as theAccessibleContextof thisTextArea
- Since:
- 1.3
 
 
- 
append(String).