java.awt

Class TextArea

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Known Direct Subclasses:
TextEditor, TextViewer

public class TextArea
extends TextComponent
implements Serializable

A TextArea is a text component capable of displaying multiple lines of user-editable text. A TextArea handles its own scrolling and can display vertical and horizontal scrollbars as navigation aids.
See Also:
Serialized Form

Nested Class Summary

protected class
TextArea.AccessibleAWTTextArea

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
Display both horiztonal and vertical scroll bars.
static int
SCROLLBARS_HORIZONTAL_ONLY
Display horizatonal scroll bar only.
static int
SCROLLBARS_NONE
Do not display scrollbars.
static int
SCROLLBARS_VERTICAL_ONLY
Display vertical scroll bar 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()
Initialize a new instance of TextArea that is empty.
TextArea(int rows, int columns)
Initialize a new instance of TextArea that is empty and can display the specified number of rows and columns of text, without the need to scroll.
TextArea(String text)
Initialize a new instance of TextArea that contains the specified text.
TextArea(String text, int rows, int columns)
Initialize a new instance of TextArea that can display the specified number of rows and columns of text, without the need to scroll.
TextArea(String text, int rows, int columns, int scrollbarVisibility)
Initialize a new instance of TextArea that initially contains the specified text.

Method Summary

void
addNotify()
Notify this object that it should create its native peer.
void
append(String str)
Append the specified text to the end of the current text.
void
appendText(String str)
Deprecated. This method is deprecated in favor of append ().
AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this TextArea.
int
getColumns()
Retrieve the number of columns that this text area would prefer to display.
Dimension
getMinimumSize()
Retrieve the minimum size for this text area.
Dimension
getMinimumSize(int rows, int columns)
Retrieve the minimum size for this text area.
Dimension
getPreferredSize()
Retrieve the preferred size for this text area.
Dimension
getPreferredSize(int rows, int columns)
Retrieve the preferred size for this text area.
int
getRows()
Retrieve the number of rows that this text area would prefer to display.
int
getScrollbarVisibility()
Retrieve the scroll bar display policy -- one of SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE.
void
insert(String str, int pos)
Insert the specified text at the specified position.
void
insertText(String str, int pos)
Deprecated. This method is deprecated in favor of insert ().
Dimension
minimumSize()
Deprecated. This method is deprecated in favor of getMinimumSize ().
Dimension
minimumSize(int rows, int columns)
Deprecated. This method is deprecated in favor of getMinimumSize (int, int).
protected String
paramString()
Retrieve a debugging string for this text area.
Dimension
preferredSize()
Deprecated. This method is deprecated in favor of getPreferredSize ().
Dimension
preferredSize(int rows, int columns)
Deprecated. This method is deprecated in favor of getPreferredSize (int, int).
void
replaceRange(String str, int start, int end)
Replace a range of characters with the specified text.
void
replaceText(String str, int start, int end)
Deprecated. This method is deprecated in favor of replaceRange ().
void
setColumns(int columns)
Set the preferred number of columns for this text area.
void
setRows(int rows)
Set the preferred number of rows for this text area.

Methods inherited from class java.awt.TextComponent

addTextListener, extends EventListener> T[] getListeners, getAccessibleContext, getCaretPosition, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, paramString, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, 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, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, 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, 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, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, 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, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, 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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

SCROLLBARS_BOTH

public static final int SCROLLBARS_BOTH
Display both horiztonal and vertical scroll bars.
Field Value:
0

SCROLLBARS_HORIZONTAL_ONLY

public static final int SCROLLBARS_HORIZONTAL_ONLY
Display horizatonal scroll bar only.
Field Value:
2

SCROLLBARS_NONE

public static final int SCROLLBARS_NONE
Do not display scrollbars.
Field Value:
3

SCROLLBARS_VERTICAL_ONLY

public static final int SCROLLBARS_VERTICAL_ONLY
Display vertical scroll bar only.
Field Value:
1

Constructor Details

TextArea

public TextArea()
Initialize a new instance of TextArea that is empty. Conceptually the TextArea has 0 rows and 0 columns but its initial bounds are defined by its peer or by the container in which it is packed. Both horizontal and vertical scrollbars will be displayed.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless () is true

TextArea

public TextArea(int rows,
                int columns)
Initialize a new instance of TextArea that is empty and can display the specified number of rows and columns of text, without the need to scroll. Both horizontal and vertical scrollbars will be displayed.
Parameters:
rows - The number of rows in this text area.
columns - The number of columns in this text area.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless () is true

TextArea

public TextArea(String text)
Initialize a new instance of TextArea that contains the specified text. Conceptually the TextArea has 0 rows and 0 columns but its initial bounds are defined by its peer or by the container in which it is packed. Both horizontal and veritcal scrollbars will be displayed. The TextArea initially contains the specified text. If text specified as null, it will be set to "".
Parameters:
text - The text to display in this text area (null permitted).
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless () is true

TextArea

public TextArea(String text,
                int rows,
                int columns)
Initialize a new instance of TextArea that can display the specified number of rows and columns of text, without the need to scroll. The TextArea initially contains the specified text. If text specified as null, it will be set to "".
Parameters:
text - The text to display in this text area (null permitted).
rows - The number of rows in this text area.
columns - The number of columns in this text area.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless () is true

TextArea

public TextArea(String text,
                int rows,
                int columns,
                int scrollbarVisibility)
Initialize a new instance of TextArea that initially contains the specified text. The TextArea can display the specified number of rows and columns of text, without the need to scroll. This constructor allows specification of the scroll bar display policy. The TextArea initially contains the specified text. If text specified as null, it will be set to "".
Parameters:
text - The text to display in this text area (null permitted).
rows - The number of rows in this text area.
columns - The number of columns in this text area.
scrollbarVisibility - The scroll bar display policy. One of SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless () is true

Method Details

addNotify

public void addNotify()
Notify this object that it should create its native peer.
Overrides:
addNotify in interface Component

append

public void append(String str)
Append the specified text to the end of the current text.
Parameters:
str - The text to append.

appendText

public void appendText(String str)

Deprecated. This method is deprecated in favor of append ().

Append the specified text to the end of the current text.
Parameters:
str - The text to append.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this TextArea. The context is created, if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface TextComponent
Returns:
the associated context

getColumns

public int getColumns()
Retrieve the number of columns that this text area would prefer to display. This value may or may not correspond to the number of columns that are actually displayed.
Returns:
The preferred number of columns.

getMinimumSize

public Dimension getMinimumSize()
Retrieve the minimum size for this text area.
Overrides:
getMinimumSize in interface Component
Returns:
The minimum size for this text field.

getMinimumSize

public Dimension getMinimumSize(int rows,
                                int columns)
Retrieve the minimum size for this text area. If the minimum size has been set, then rows and columns are used in the calculation.
Parameters:
rows - The number of rows to use in the minimum size calculation.
columns - The number of columns to use in the minimum size calculation.
Returns:
The minimum size for this text area.

getPreferredSize

public Dimension getPreferredSize()
Retrieve the preferred size for this text area.
Overrides:
getPreferredSize in interface Component
Returns:
The preferred size for this text field.

getPreferredSize

public Dimension getPreferredSize(int rows,
                                  int columns)
Retrieve the preferred size for this text area. If the preferred size has been set, then rows and columns are used in the calculation.
Parameters:
rows - The number of rows to use in the preferred size calculation.
columns - The number of columns to use in the preferred size calculation.
Returns:
The preferred size for this text area.

getRows

public int getRows()
Retrieve the number of rows that this text area would prefer to display. This value may or may not correspond to the number of rows that are actually displayed.
Returns:
The preferred number of rows.

getScrollbarVisibility

public int getScrollbarVisibility()
Retrieve the scroll bar display policy -- one of SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE.
Returns:
The current scroll bar display policy.

insert

public void insert(String str,
                   int pos)
Insert the specified text at the specified position. The first character in the text area is at position zero.
Parameters:
str - The text to insert.
pos - The position at which to insert text.

insertText

public void insertText(String str,
                       int pos)

Deprecated. This method is deprecated in favor of insert ().

Insert the specified text at the specified position. The first character in the text area is at position zero.
Parameters:
str - The text to insert.
pos - The position at which to insert text.

minimumSize

public Dimension minimumSize()

Deprecated. This method is deprecated in favor of getMinimumSize ().

Retrieve the minimum size for this text area.
Overrides:
minimumSize in interface Component
Returns:
The minimum size for this text area.

minimumSize

public Dimension minimumSize(int rows,
                             int columns)

Deprecated. This method is deprecated in favor of getMinimumSize (int, int).

Retrieve the minimum size for this text area. If the minimum size has been set, then rows and columns are used in the calculation.
Parameters:
rows - The number of rows to use in the minimum size calculation.
columns - The number of columns to use in the minimum size calculation.
Returns:
The minimum size for this text area.

paramString

protected String paramString()
Retrieve a debugging string for this text area.
Overrides:
paramString in interface TextComponent
Returns:
A debugging string for this text area.

preferredSize

public Dimension preferredSize()

Deprecated. This method is deprecated in favor of getPreferredSize ().

Retrieve the preferred size for this text area.
Overrides:
preferredSize in interface Component
Returns:
The preferred size for this text field.

preferredSize

public Dimension preferredSize(int rows,
                               int columns)

Deprecated. This method is deprecated in favor of getPreferredSize (int, int).

Retrieve the preferred size for this text area. If the preferred size has been set, then rows and columns are used in the calculation.
Parameters:
rows - The number of rows to use in the preferred size calculation.
columns - The number of columns to use in the preferred size calculation.
Returns:
The preferred size for this text area.

replaceRange

public void replaceRange(String str,
                         int start,
                         int end)
Replace a range of characters with the specified text. The character at the start position will be replaced, unless start == end. The character at the end posistion will not be replaced. The first character in the text area is at position zero. The length of the replacement text may differ from the length of the text that is replaced.
Parameters:
str - The new text for the range.
start - The start position of the replacement range.
end - The end position of the replacement range.

replaceText

public void replaceText(String str,
                        int start,
                        int end)

Deprecated. This method is deprecated in favor of replaceRange ().

Replace a range of characters with the specified text. The character at the start position will be replaced, unless start == end. The character at the end posistion will not be replaced. The first character in the text area is at position zero. The length of the replacement text may differ from the length of the text that is replaced.
Parameters:
str - The new text for the range.
start - The start position of the replacement range.
end - The end position of the replacement range.

setColumns

public void setColumns(int columns)
Set the preferred number of columns for this text area. This method does not cause the number of columns displayed by the text area to be updated, if the text area is currently visible.
Parameters:
columns - The preferred number of columns.
Throws:
IllegalArgumentException - If columns is less than zero.

setRows

public void setRows(int rows)
Set the preferred number of rows for this text area. This method does not cause the number of columns displayed by the text area to be updated, if the text area is currently visible.
Parameters:
rows - The preferred number of rows.
Throws:
IllegalArgumentException - If rows is less than zero.

TextArea.java -- A multi-line text entry component Copyright (C) 1999, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.