All for Joomla All for Webmasters

JTextArea class

The JTextArea class is used to create a text area. It is a multiline area that displays the plain text only.

Commonly used Constructors:

  • JTextArea(): creates a text area that displays no text initially.
  • JTextArea(String s): creates a text area that displays specified text initially.
  • JTextArea(int row, int column): creates a text area with the specified number of rows and columns that displays no text initially..
  • JTextArea(String s, int row, int column): creates a text area with the specified number of rows and columns that displays specified text.

Commonly used methods of JTextArea class:

1) public void setRows(int rows): is used to set specified number of rows.
2) public void setColumns(int cols):: is used to set specified number of columns.
3) public void setFont(Font f): is used to set the specified font.
4) public void insert(String s, int position): is used to insert the specified text on the specified position.
5) public void append(String s): is used to append the given text to the end of the document.

Example of JTextField class:

  1. import java.awt.Color;
  2. import javax.swing.*;
  3. public class TArea {
  4.     JTextArea area;
  5.     JFrame f;
  6.     TArea(){
  7.     f=new JFrame();
  8.     area=new JTextArea(300,300);
  9.     area.setBounds(10,30,300,300);
  10.     area.setBackground(Color.black);
  11.     area.setForeground(Color.white);
  12.     f.add(area);
  13.     f.setSize(400,400);
  14.     f.setLayout(null);
  15.     f.setVisible(true);
  16. }
  17.     public static void main(String[] args) {
  18.         new TArea();
  19.     }
  20. }
PinIt
submit to reddit

Leave a Reply

Top