Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class TextArea

Constructors , Methods , Footnotes

public  class  java.awt.TextArea
    extends  java.awt.TextComponent  
{
        // Constructors
    public TextArea();	
    public TextArea(int  rows, int  cols);	
    public TextArea(String  text);	
    public TextArea(String  text, int  rows, int cols);	

        // Methods
    public void addNotify();	
    public void appendText(String  str);	
    public int getColumns();	
    public int getRows();	
    public void insertText(String  str, int  pos);	
    public Dimension minimumSize();	
    public Dimension minimumSize(int  rows, int  cols);	
    protected String paramString();	
    public Dimension preferredSize();	
    public Dimension preferredSize(int  rows, int  cols);	
    public void replaceText(String  str, int  start, int  end);	
}

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:

new TextArea("Hello", 5, 40); 

produces the text area shown below:

When(1) the text area receives or loses the focus, AWT sends a "got focus" or "lost focus" event to the text area. An application should override the gotfocus method or the lostFocus method 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.

ParameterDescription
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.

ParameterDescription
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.

ParameterDescription
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 of this object's toolkit in order to create a TextAreaPeer 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 .


appendText

public void appendText(String  str) 

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

ParameterDescription
str the text to append

See Also: insertText .


getColumns

public int getColumns() 

Return Value:

Returns the number of columns in this text area.


getRows

public int getRows() 

Return Value:

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.

ParameterDescription
str the text to insert
pos the position at which to insert the text

See Also: setText in class TextComponent replaceText .


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 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 is called to determine the minimum size.

Return Value:

Returns the minimum dimensions needed for this text area.

Overrides:

minimumSize in class Component .


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 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 is called to determine the minimum size.

Return Value:

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

ParameterDescription
rows the number of rows
cols the number of columns


paramString

protected String paramString() 

Returns the parameter string representing the state of this text area. This string is useful for debugging.

Return Value:

Returns the parameter string of this text area.

Overrides:

paramString in class TextComponent .


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 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 is called to determine the preferred size.

Return Value:

Returns the preferred dimensions needed for this text area.

Overrides:

preferredSize in class Component .


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 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 is called to determine the preferred size.

Return Value:

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

ParameterDescription
rows the number of rows
cols the number of 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.

ParameterDescription
str the replacement text
start the start position
end the end position

See Also: insertText .


Footnotes

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

Top© 1996 Sun Microsystems, Inc. All rights reserved.