Introduction java.awt.TextArea Constructors and Methods
Here is an example of using TextArea in AWT in Java. These examples show you how to create AWT TextAreas using all the constructors and will also introduce some methods of the java.awt.TextArea class that are useful for further implementation.
What is a TextArea?
A Text Area is a GUI component that is used to store multiple rows of text unlike a Text Field.
java.awt.TextArea Constructors
public TextArea(String text)
public TextArea(int rows, int columns)
public TextArea(String text, int rows, int columns)
public TextArea(String text, int rows, int columns, int scrollbars)
All the constructors throw java.awt.HeadlessException.
java.awt.TextArea Methods
Insert text in the textarea at the particular position.
public void insert(java.lang.String text, int position);
public synchronized void insertText(java.lang.String text, int position);
Append text in the textarea.
public void append(java.lang.String text);
public synchronized void appendText(java.lang.String text);
Replace text between given start and end points with the given text.
public void replaceRange(java.lang.String text, int start, int end);
public synchronized void replaceText(java.lang.String text, int start, int end);
Set/Get no.of rows in the TextArea.
public int getRows();
public void setRows(int rows);
Set/Get no.of columns in the TextArea.
public int getColumns();
public void setColumns(int columns);
Get the Scrollbar constant value for a textarea. See down for Scrollbar constants.
public int getScrollbarVisibility();
Set/Get Text in the TextArea. If text exists, then the text in it will be replaced with the given text.
public void setText(String text);
public String getText();
java.awt.TextArea Constants
Scrollbars Constants
public static final int SCROLLBARS_BOTH; (Value 0)
public static final int SCROLLBARS_VERTICAL_ONLY; (Value 1)
public static final int SCROLLBARS_HORIZONTAL_ONLY; (Value 2)
public static final int SCROLLBARS_NONE; (Value 3)
-------------------------------------
Output
-------------------------------------
No.of rows of ta 10
No. of cols for ta 10
Scrollbar for ta4 2
No comments:
Post a Comment