Monday, 13 April 2015

JTextArea class

JTextArea class (Swing Tutorial):
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.      
4.    public class TArea {  
5.        JTextArea area;  
6.        JFrame f;  
7.        TArea(){  
8.        f=new JFrame();  
9.              
10.     area=new JTextArea(300,300);  
11.     area.setBounds(10,30,300,300);  
12.       
13.     area.setBackground(Color.black);  
14.     area.setForeground(Color.white);  
15.           
16.     f.add(area);  
17.       
18.     f.setSize(400,400);  
19.     f.setLayout(null);  
20.     f.setVisible(true);  
21. }  
22.     public static void main(String[] args) {  
23.         new TArea();  
24.     }  

25. }  

No comments:

Post a Comment

Access attributes in component

NOTE: To access an attribute in a  component , use expressions as  {! v.<Attribute Name>} . ----------------------------------------...