by Dinesh Thakur Category: AWT and Applets

The TextArea component is similar to the TextField component except that it allows to display and edit multiple lines of plaintext. The TextArea component has certain number of rows and columns that determines its size. If all the text cannot be displayed in the available space in the component, even then scrollbars are not automatically added. In order to add scrollbars, you must insert it into a Scrollpane.

import java.awt.*;

class TextAreaExample extends Frame
{
     TextAreaExample()
     {
          setLayout(new FlowLayout());
          Label label = new Label("Comment Box");
          TextArea txtArea = new TextArea("TextArea",3,15); //TextArea with 3 rows and 15 columms
          add(label);
          add(txtArea);
      }
}
   class TextAreaJavaExample
   {
         public static void main(String args[])
        {
               TextAreaExample frame = new TextAreaExample();
               frame.setTitle("TextArea in Java Example");
               frame.setSize(350,150);
               frame.setVisible(true);
        }
   }

TextArea in Java Example

Popular Article