Turn Desktop View Off
by Dinesh Thakur

This component, known as multiline input box or memo, allows creation of an area for entering and editing text containing multiple lines in order to can even contain more text than can be displayed. Belongs to the class java.awt.TextArea and java.awt.TextField as the component shares the characteristics of their ancestral component java.awt.TextComponent.

The TextArea component can be adjusted to allow or not to issue and display scroll bars to help control the text display. The class  java.awt.TextArea contain, among others, the following constructors and methods:

Method

Description

TextArea ( )

Constructs a component with both without text scrollbars .

TextArea ( int , int )

Constructs a component capable of displaying text without the number of rows and columns of text specified with the two scroll bars .

TextArea ( String )

Constructs a component containing the text specified with the two scroll bars .

TextArea (String , int , int )

Constructs a component with text data can display the number of rows and columns of text specified with the two scroll bars.

TextArea (String ,int,int,int )

Constructs a component with text data can display the number of rows and columns of text specified and also the scrollbars indicated.

append ( String )

Appends the given text to the end of the text contained by component.

getColumns ( )

Gets the number of columns of text .

getRows ( )

Gets the number of lines of text .

insert ( String , int )

Inserts the given text at the position indicated .

replaceRange ( String , int , int )

Replace the existing text between positions indicated by the given text .

SetColumns ( int )

Specifies the number of text columns .

SetRows ( int )

Specifies the number of lines of text .

The display of scrollbars can not be modified after the construction of component. Its specification uses a constructor that accepts as a parameter the constant TextArea.SCROLLBARS_BOTH, TextArea.SCROLLBARS_NONE,TextArea.SCROLLBARS_VERTICAL_ONLY,TextArea.SCROLLBARS_HORIZONTAL_ONLY.

import java.awt.*;

import java.awt.event.*;
import java.applet.*;
/* <APPLET CODE ="TextareaExampleAwt.class" WIDTH=300 HEIGHT=200> </APPLET> */
public class TextareaExampleAwt extends Applet implements ActionListener
  {
       String t;
       Button b1,b2;
       TextArea txt;
        public void init()
            {
                txt=new TextArea("Welcome to Java",2,30);
                b1=new Button("Upper Case");
                b2=new Button("Lower Case");
                add(txt);
                add(b1);
                add(b2);
                b1.addActionListener(this);
                b2.addActionListener(this);
            }
                public void actionPerformed(ActionEvent event)
                    {
                      String k=event.getActionCommand();
                       if(k.equals("Upper Case"));
                         {
                             t=txt.getText();
                             t=t.toUpperCase();
                             txt.setText(t);
                         }
                              if(k.equals("Lower case"))
                               {
                                   t=txt.getText();
                                   t=t.toLowerCase();
                                   txt.setText(t);
                               }
                   }
   }                        

Textarea Example in Java Awt