Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Top
Back
Next
Online Training
shadowSearchFAQFeedback

TextArea

A TextArea is a multirow text field that displays a single string of characters, where a newline ends each row. The width and height of the field is set at construction, but the text can be scrolled up and down and left and right.



Corresponding source code:

import java.applet.*;
import java.awt.*;
public class TextAreaWidget extends Applet {
    public void init() {
        TextArea disp = new TextArea("A TextArea", 3, 30);
        add(disp);
    }
}

Methods:

  • public TextArea(String text, int rows, int cols)
    Creates a TextArea with the specified number of rows and columns and some initial text.
  • public void appendText(String str)
    Adds some text to the end of the current text.
  • public void insertText(String str, int pos)
    Inserts some text at a particular String index in the TextArea.

There is no predefined way to set a particular row of text. Carriage returns are used to separate the rows, which must be counted to get to the nth row.

Related exercises: