TextArea class handles the multiline of text. It is the subclass of TextComponent. The constructors for TextArea are Listed below:
TextArea() - It constructs an empty text area.
TextArea(String text) - It constructs a text area with text as initial context .
TextArea(int rows, int cols) - constructs an empty text area with the specified number of rows and columns.
TextArea(String text, int rows, int cols, int Scrollbarconstant) - constructs a text area whose initial content is text and the specified number of rows and columns with scrollbar. The scrollbar should be one of the following:
TextArea.SCROLLBARS_BOTH
TextArea.SCROLLBARS_NONE
TextArea.SCROLLBARS_HORIZONTAL_ONLY
TextArea.SCROLLBARS_VERTICAL_ONLY
append(String s) - this method is used to add the text at the end of a string in Text area.
insert(String s, int position) - to insert a text at particular position.
setEditable(boolean b) - Makes the text area editable, if true is passed as the argument.
Example:
import java.applet.*;
import java.awt.*;
public class TextAreaDemo extends Applet
{
public void init()
{
TextArea ta=new TextArea(5, 8);
Label l1=new Label("Text Area", Label.CENTER);
ta.setText("This\nis the \nTest\nfor Text Area\nwith\nnon editable \nmode");
add(l1);
add(ta);
ta.setEditable(false);
}
}
/*
* <applet code="TextAreaDemo.class" width=250 height=150>
* </applet>
*/
0 comments :
Post a Comment