This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt
class TextArea

java.lang.Object extended by java.awt.Component extended by java.awt.TextComponent extended by java.awt.TextArea
All Implemented Interfaces:
MenuContainer, ImageObserver, Serializable, Accessible

Most common way to construct:

TextArea textArea = new TextArea(10, 20);

Based on 63 examples


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:

A TextArea showing the word 'Hello!'

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

          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.
TextArea(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(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

          Creates the TextArea's peer.
 void

          Appends the given text to the text area's current text.
 void

          
 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

          Returns the number of rows in the text area.
 int

          Returns an enumerated value that indicates which scroll bars the text area uses.
 void
insert(String str, int pos)

          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.awt.TextComponent
addNotify, addTextListener, enableInputMethods, getAccessibleContext, getBackground, getCaretPosition, getInputMethodRequests, getListeners, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, paramString, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, 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, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, 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, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCROLLBARS_BOTH

public static final int SCROLLBARS_BOTH
Create and display both vertical and horizontal scrollbars.

SCROLLBARS_HORIZONTAL_ONLY

public static final int SCROLLBARS_HORIZONTAL_ONLY
Create and display horizontal scrollbar only.

SCROLLBARS_NONE

public static final int SCROLLBARS_NONE
Do not create or display any scrollbars for the text area.

SCROLLBARS_VERTICAL_ONLY

public static final int SCROLLBARS_VERTICAL_ONLY
Create and display vertical scrollbar only.
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 {@link #SCROLLBARS_BOTH}, so both vertical and horizontal scrollbars will be visible for this text area.

Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true

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 {@link #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 - if GraphicsEnvironment.isHeadless returns true

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 {@link #SCROLLBARS_BOTH}, so both vertical and horizontal scrollbars will be visible for this text area.

Parameters:
text - the text to be displayed; if text is null, the empty string "" will be displayed
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true

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 {@link #SCROLLBARS_BOTH}, so both vertical and horizontal scrollbars will be visible for this text area.

Parameters:
text - the text to be displayed; if text is null, the empty string "" will be displayed
rows - the number of rows
columns - the number of columns
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true

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 the scrollbars argument:

Any other value for the 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}.

Parameters:
text - the text to be displayed; if text is null, the empty string "" will be displayed
rows - 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 area
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true
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 in class TextComponent

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

appendText

public synchronized void appendText(String str)
Parameters:
str

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the AccessibleContext associated with this TextArea. For text areas, the AccessibleContext takes the form of an AccessibleAWTTextArea. A new AccessibleAWTTextArea instance is created if necessary.

Overrides:
getAccessibleContext in class TextComponent
Returns:
an AccessibleAWTTextArea that serves as the AccessibleContext of this TextArea

getColumns

public int getColumns()
Returns the number of columns in this text area.

Returns:
the number of columns in the text area

getMinimumSize

public Dimension getMinimumSize()
Determines the minimum size of this text area.

Overrides:
getMinimumSize in class Component
Returns:
the preferred dimensions needed for this text area

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

getPreferredSize

public Dimension getPreferredSize()
Determines the preferred size of this text area.

Overrides:
getPreferredSize in class Component
Returns:
the preferred dimensions needed for this text area

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

getRows

public int getRows()
Returns the number of rows in the text area.

Returns:
the number of rows in the text area

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

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

insertText

public synchronized void insertText(String str,
                                    int pos)
Parameters:
str
pos

minimumSize

public Dimension minimumSize()
Overrides:
minimumSize in class Component

minimumSize

public Dimension minimumSize(int rows,
                             int columns)
Parameters:
rows
columns

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 in class TextComponent
Returns:
the parameter string of this text area

preferredSize

public Dimension preferredSize()
Overrides:
preferredSize in class Component

preferredSize

public Dimension preferredSize(int rows,
                               int columns)
Parameters:
rows
columns

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

replaceText

public synchronized void replaceText(String str,
                                     int start,
                                     int end)
Parameters:
str
start
end

setColumns

public void setColumns(int columns)
Sets the number of columns for this text area.

Parameters:
columns - the number of columns

setRows

public void setRows(int rows)
Sets the number of rows for this text area.

Parameters:
rows - the number of rows


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.