Packages  This Package  Prev  Next  Index  

§1.38 Class TextArea

public  class  java.awt.TextArea
    extends  java.awt.TextComponent  (II-§1.39)
{
        // Constructors
    public TextArea();	§1.38.1
    public TextArea(int  rows, int  cols);	§1.38.2
    public TextArea(String  text);	§1.38.3
    public TextArea(String  text, int  rows, int cols);	§1.38.4

        // Methods
    public void addNotify();	§1.38.5
    public void appendText(String  str);	§1.38.6
    public int getColumns();	§1.38.7
    public int getRows();	§1.38.8
    public void insertText(String  str, int  pos);	§1.38.9
    public Dimension minimumSize();	§1.38.10
    public Dimension minimumSize(int  rows, int  cols);	§1.38.11
    protected String paramString();	§1.38.12
    public Dimension preferredSize();	§1.38.13
    public Dimension preferredSize(int  rows, int  cols);	§1.38.14
    public void replaceText(String  str, int  start, int  end);	§1.38.15
}
A text area is a multiline area for displaying text. It can be set to allow editing or to be read-only.

For example, the following code code:

produces the text area shown below:

When1 the text area receives or loses the focus, AWT sends a "got focus" (II-§1.14.12) or "lost focus" (II-§1.14.20) event to the text area. An application should override the gotfocus method (II-§1.10.21) or the lostFocus method (II-§1.10.39) of the text area in order to cause some action to occur.

Most user interfaces use an external event (such as clicking on a button) to trigger an action on the text area.


Constructors

TextArea

public TextArea()
Constructs a new text area.

TextArea

public TextArea(int rows, int cols)
Constructs a new text area with the specified number of rows and columns.
Parameters:
rows - the number of rows
cols - the number of columns

TextArea

public TextArea(String text)
Constructs a new text area with the specified text displayed.
Parameters:
text - the text to be displayed

TextArea

public TextArea(String text, int rows, int cols)
Constructs a new TextArea with the specified text, and the specified number of rows and columns.
Parameters:
text - the text to be displayed
rows - the number of rows
cols - the number of cols

Methods

addNotify

public void addNotify()
This method calls the createTextArea method (II-§1.41.19) of this object's toolkit (II-§1.10.20) in order to create a TextAreaPeer (II-§3.19) for this text area. This peer allows the application to change the look of a text area without changing its functionality.


Most applications do not call this method directly.
Overrides:
addNotify in class Component (II-§1.10.2).

appendText

public void appendText(String str)
Appends the given text to this text area's current text.
Parameters:
str - the text to append
See Also:
insertText (II-§1.38.9).

getColumns

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

getRows

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

insertText

public void insertText(String str, int pos)
Inserts the specified text at the specified position in this text area.
Parameters:
str - the text to insert
pos - the position at which to insert the text
See Also:
setText in class TextComponent (II-§1.39.11)
replaceText (II-§1.38.15).

minimumSize

public Dimension minimumSize()
Determines the minimum size of this text area. If the application has specified both the number of rows and the number of columns for this text area, and both are greater than zero, then the text area's peer's minimumSize method (II-§3.19.2) is called with the number of rows and columns in order to determine the minimum size.


If the text area does not have a peer, or if the number of rows or number of columns specified by the application is less than or equal to zero, the superclass's minimumSize method (II-§1.10.40) is called to determine the minimum size.

Returns:
the minimum dimensions needed for this text area.
Overrides:
minimumSize in class Component (II-§1.10.40).

minimumSize

public Dimension minimumSize(int rows, int cols)
Determines the minimum size of a text area with the specified number of rows and columns. This text area's peer's minimumSize method (II-§3.19.2) is called with the number of rows and columns in order to determine the minimum size.


If this text area does not have a peer, the superclass's minimumSize method (II-§1.10.40) is called to determine the minimum size.

Parameters:
rows - the number of rows
cols - the number of columns
Returns:
the minimum dimensions needed to display the text area with the specified number of rows and columns.

paramString

protected String paramString()
Returns the parameter string representing the state of this text area. This string is useful for debugging.
Returns:
the parameter string of this text area.
Overrides:
paramString in class TextComponent (II-§1.39.6).

preferredSize

public Dimension preferredSize()
Determines the preferred size of this text area. If the application has specified both the number of rows and the number of columns for this text area, and both are greater than zero, then the text area's peer's preferredSize method (II-§3.19.3) is called with the number of rows and columns in order to determine the preferred size.


If this text area does not have a peer, or if the number of rows or number of columns specified by the application is less than or equal to zero, the superclass's preferredSize method (II-§1.10.53) is called to determine the preferred size.

Returns:
the preferred dimensions needed for this text area.
Overrides:
preferredSize in class Component (II-§1.10.53).

preferredSize

public Dimension preferredSize(int rows, int cols)
Determines the preferred size of a text area with the specified number of rows and columns. This text area's peer's preferredSize method (II-§3.19.3) is called with the number of rows and columns in order to determine the preferred size.


If this text area does not have a peer the superclass's preferredSize method (II-§1.10.53) is called to determine the preferred size.

Parameters:
rows - the number of rows
cols - the number of columns
Returns:
the preferred dimensions needed to display the text area with the specified number of rows and columns.

replaceText

public void replaceText(String str, int start, int end)
Replaces the text in the text area from the start (inclusive) index to the end (exclusive) index with the new text specified.
Parameters:
str - the replacement text
start - the start position
end - the end position
See Also:
insertText (II-§1.38.9).

1 In Java 1.0, the AWT does not send mouse, keyboard, or focus events to a text area. In Java 1.1, the AWT sends the text area all mouse, keyboard, and focus events that occur over it.

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com