Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: TextArea [javadoc | source]
java.lang.Object
   java.awt.Component
      java.awt.TextComponent
         java.awt.TextArea

All Implemented Interfaces:
    Accessible, MenuContainer, Serializable, ImageObserver

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  TextArea.AccessibleAWTTextArea  This class implements accessibility support for the TextArea class. It provides an implementation of the Java Accessibility API appropriate to text area user-interface elements. 
Field Summary
 int rows    The number of rows in the TextArea. This parameter will determine the text area's height. Guaranteed to be non-negative. 
 int columns    The number of columns in the TextArea. A column is an approximate average character width that is platform-dependent. This parameter will determine the text area's width. Guaranteed to be non-negative. 
public static final  int SCROLLBARS_BOTH    Create and display both vertical and horizontal scrollbars.
    since: JDK1.1 -
 
public static final  int SCROLLBARS_VERTICAL_ONLY    Create and display vertical scrollbar only.
    since: JDK1.1 -
 
public static final  int SCROLLBARS_HORIZONTAL_ONLY    Create and display horizontal scrollbar only.
    since: JDK1.1 -
 
public static final  int SCROLLBARS_NONE    Do not create or display any scrollbars for the text area.
    since: JDK1.1 -
 
Fields inherited from java.awt.TextComponent:
text,  editable,  selectionStart,  selectionEnd,  backgroundSetByClientCode,  textListener
Fields inherited from java.awt.Component:
peer,  parent,  appContext,  x,  y,  width,  height,  foreground,  background,  font,  peerFont,  cursor,  locale,  bufferStrategy,  ignoreRepaint,  visible,  enabled,  dropTarget,  popups,  focusTraversalKeys,  LOCK,  minSize,  minSizeSet,  prefSize,  prefSizeSet,  maxSize,  maxSizeSet,  componentOrientation,  newEventsOnly,  componentListener,  focusListener,  hierarchyListener,  hierarchyBoundsListener,  keyListener,  mouseListener,  mouseMotionListener,  mouseWheelListener,  inputMethodListener,  windowClosingException,  actionListenerK,  adjustmentListenerK,  componentListenerK,  containerListenerK,  focusListenerK,  itemListenerK,  keyListenerK,  mouseListenerK,  mouseMotionListenerK,  mouseWheelListenerK,  textListenerK,  ownedWindowK,  windowListenerK,  inputMethodListenerK,  hierarchyListenerK,  hierarchyBoundsListenerK,  windowStateListenerK,  windowFocusListenerK,  eventMask,  isInc,  incRate,  TOP_ALIGNMENT,  CENTER_ALIGNMENT,  BOTTOM_ALIGNMENT,  LEFT_ALIGNMENT,  RIGHT_ALIGNMENT,  isPacked,  backgroundEraseDisabled,  eventCache,  accessibleContext
Constructor:
 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 - if GraphicsEnvironment.isHeadless returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless()
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
 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; if text is null, the empty string "" will be displayed
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless()
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
 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 - if GraphicsEnvironment.isHeadless returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless()
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
 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; 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
    Also see:
    java.awt.GraphicsEnvironment#isHeadless()
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
 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:

    • SCROLLBARS_BOTH,
    • SCROLLBARS_VERTICAL_ONLY,
    • SCROLLBARS_HORIZONTAL_ONLY,
    • SCROLLBARS_NONE.
    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 #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
    Also see:
    java.awt.GraphicsEnvironment#isHeadless()
    since: JDK1.1 -
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
Method from java.awt.TextArea Summary:
addNotify,   append,   appendText,   constructComponentName,   getAccessibleContext,   getColumns,   getMinimumSize,   getMinimumSize,   getPreferredSize,   getPreferredSize,   getRows,   getScrollbarVisibility,   insert,   insertText,   minimumSize,   minimumSize,   paramString,   preferredSize,   preferredSize,   replaceRange,   replaceText,   setColumns,   setRows
Methods from java.awt.TextComponent:
addNotify,   addTextListener,   areInputMethodsEnabled,   enableInputMethods,   eventEnabled,   getAccessibleContext,   getBackground,   getCaretPosition,   getCharacterBounds,   getIndexAtPoint,   getInputMethodRequests,   getListeners,   getSelectedText,   getSelectionEnd,   getSelectionStart,   getText,   getTextListeners,   isEditable,   paramString,   processEvent,   processTextEvent,   removeNotify,   removeTextListener,   select,   selectAll,   setBackground,   setCaretPosition,   setEditable,   setSelectionEnd,   setSelectionStart,   setText
Methods from java.awt.Component:
action,   add,   addComponentListener,   addFocusListener,   addHierarchyBoundsListener,   addHierarchyListener,   addInputMethodListener,   addKeyListener,   addMouseListener,   addMouseMotionListener,   addMouseWheelListener,   addNotify,   addPropertyChangeListener,   addPropertyChangeListener,   adjustListeningChildrenOnParent,   applyComponentOrientation,   applyCompoundShape,   applyCurrentShape,   areBoundsValid,   areFocusTraversalKeysSet,   areInputMethodsEnabled,   autoProcessMouseWheel,   bounds,   canBeFocusOwner,   canBeFocusOwnerRecursively,   checkGD,   checkImage,   checkImage,   checkTreeLock,   checkWindowClosingException,   clearCurrentFocusCycleRootOnHide,   clearMostRecentFocusOwnerOnHide,   coalesceEvents,   constructComponentName,   contains,   contains,   containsFocus,   countHierarchyMembers,   createBufferStrategy,   createBufferStrategy,   createHierarchyEvents,   createImage,   createImage,   createVolatileImage,   createVolatileImage,   deliverEvent,   disable,   disableEvents,   dispatchEvent,   dispatchEventImpl,   dispatchMouseWheelToAncestor,   doLayout,   enable,   enable,   enableEvents,   enableInputMethods,   eventEnabled,   eventTypeEnabled,   findUnderMouseInWindow,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   getAccessControlContext,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getAlignmentX,   getAlignmentY,   getBackBuffer,   getBackground,   getBaseline,   getBaselineResizeBehavior,   getBounds,   getBounds,   getBoundsOp,   getBufferStrategy,   getColorModel,   getComponentAt,   getComponentAt,   getComponentListeners,   getComponentOrientation,   getContainer,   getContainingWindow,   getCursor,   getCursor_NoClientCode,   getDropTarget,   getFocusCycleRootAncestor,   getFocusListeners,   getFocusTraversalKeys,   getFocusTraversalKeysEnabled,   getFocusTraversalKeys_NoIDCheck,   getFont,   getFontMetrics,   getFont_NoClientCode,   getForeground,   getGraphics,   getGraphicsConfiguration,   getGraphicsConfiguration_NoClientCode,   getGraphics_NoClientCode,   getHWPeerAboveMe,   getHeight,   getHierarchyBoundsListeners,   getHierarchyListeners,   getIgnoreRepaint,   getInputContext,   getInputMethodListeners,   getInputMethodRequests,   getKeyListeners,   getListeners,   getLocale,   getLocation,   getLocation,   getLocationOnScreen,   getLocationOnScreen_NoTreeLock,   getLocationOnWindow,   getMaximumSize,   getMinimumSize,   getMouseListeners,   getMouseMotionListeners,   getMousePosition,   getMouseWheelListeners,   getName,   getNativeContainer,   getNextFocusCandidate,   getNormalShape,   getObjectLock,   getOpaqueShape,   getParent,   getParent_NoClientCode,   getPeer,   getPreferredSize,   getPropertyChangeListeners,   getPropertyChangeListeners,   getSiblingIndexAbove,   getSiblingIndexBelow,   getSize,   getSize,   getToolkit,   getToolkitImpl,   getTraversalRoot,   getTreeLock,   getWidth,   getX,   getY,   gotFocus,   handleEvent,   hasFocus,   hide,   imageUpdate,   initializeFocusTraversalKeys,   inside,   invalidate,   invalidateIfValid,   invalidateParent,   isAutoFocusTransferOnDisposal,   isBackgroundSet,   isCoalescingEnabled,   isCursorSet,   isDisplayable,   isDoubleBuffered,   isEnabled,   isEnabledImpl,   isFocusCycleRoot,   isFocusOwner,   isFocusTraversable,   isFocusTraversableOverridden,   isFocusable,   isFontSet,   isForegroundSet,   isInstanceOf,   isLightweight,   isMaximumSizeSet,   isMinimumSizeSet,   isMixingNeeded,   isNonOpaqueForMixing,   isOpaque,   isPreferredSizeSet,   isRecursivelyVisible,   isSameOrAncestorOf,   isShowing,   isValid,   isVisible,   isVisible_NoClientCode,   keyDown,   keyUp,   layout,   lightweightPaint,   lightweightPrint,   list,   list,   list,   list,   list,   locate,   location,   lostFocus,   minimumSize,   mixOnHiding,   mixOnReshaping,   mixOnShowing,   mixOnValidating,   mixOnZOrderChanging,   mouseDown,   mouseDrag,   mouseEnter,   mouseExit,   mouseMove,   mouseUp,   move,   nextFocus,   numListening,   paint,   paintAll,   paintHeavyweightComponents,   paramString,   pointRelativeToComponent,   postEvent,   postsOldMouseEvents,   preferredSize,   prepareImage,   prepareImage,   print,   printAll,   printHeavyweightComponents,   processComponentEvent,   processEvent,   processFocusEvent,   processHierarchyBoundsEvent,   processHierarchyEvent,   processInputMethodEvent,   processKeyEvent,   processMouseEvent,   processMouseMotionEvent,   processMouseWheelEvent,   relocateComponent,   remove,   removeComponentListener,   removeFocusListener,   removeHierarchyBoundsListener,   removeHierarchyListener,   removeInputMethodListener,   removeKeyListener,   removeMouseListener,   removeMouseMotionListener,   removeMouseWheelListener,   removeNotify,   removePropertyChangeListener,   removePropertyChangeListener,   repaint,   repaint,   repaint,   repaint,   requestFocus,   requestFocus,   requestFocus,   requestFocus,   requestFocusHelper,   requestFocusHelper,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   reshape,   resize,   resize,   revalidate,   setAutoFocusTransferOnDisposal,   setBackground,   setBounds,   setBounds,   setBoundsOp,   setComponentOrientation,   setCursor,   setDropTarget,   setEnabled,   setFocusTraversalKeys,   setFocusTraversalKeysEnabled,   setFocusTraversalKeys_NoIDCheck,   setFocusable,   setFont,   setForeground,   setGraphicsConfiguration,   setIgnoreRepaint,   setLocale,   setLocation,   setLocation,   setMaximumSize,   setMinimumSize,   setName,   setPreferredSize,   setRequestFocusController,   setSize,   setSize,   setVisible,   show,   show,   size,   subtractAndApplyShape,   subtractAndApplyShapeBelowMe,   toString,   transferFocus,   transferFocus,   transferFocusBackward,   transferFocusBackward,   transferFocusUpCycle,   update,   updateCursorImmediately,   updateGraphicsData,   updateZOrder,   validate
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.TextArea Detail:
 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.
 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.

 public synchronized  void appendText(String str) 
Deprecated! As - of JDK version 1.1, replaced by append(String).

 String constructComponentName() 
    Construct a name for this component. Called by getName when the name is null.
 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.
 public int getColumns() 
    Returns the number of columns in this text area.
 public Dimension getMinimumSize() 
    Determines the minimum size of this text area.
 public Dimension getMinimumSize(int rows,
    int columns) 
    Determines the minimum size of a text area with the specified number of rows and columns.
 public Dimension getPreferredSize() 
    Determines the preferred size of this text area.
 public Dimension getPreferredSize(int rows,
    int columns) 
    Determines the preferred size of a text area with the specified number of rows and columns.
 public int getRows() 
    Returns the number of rows in the text area.
 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.

 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.

 public synchronized  void insertText(String str,
    int pos) 
Deprecated! As - of JDK version 1.1, replaced by insert(String, int).

 public Dimension minimumSize() 
Deprecated! As - of JDK version 1.1, replaced by getMinimumSize().

 public Dimension minimumSize(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. 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.
 public Dimension preferredSize() 
Deprecated! As - of JDK version 1.1, replaced by getPreferredSize().

 public Dimension preferredSize(int rows,
    int columns) 
Deprecated! As - of JDK version 1.1, replaced by getPreferredSize(int, int).

 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.

 public synchronized  void replaceText(String str,
    int start,
    int end) 
Deprecated! As - of JDK version 1.1, replaced by replaceRange(String, int, int).

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