Home Java Example Java Swing How to Create Text Area In Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

How to Create Text Area In Java

Advertisement
In this section, you will learn how to create Text Area in Java. This section provides you a complete code of the program for illustrating the topic.

How to Create Text Area In Java

     

In this section, you will learn how to create Text Area in Java. This section provides you a complete code of the program for illustrating the topic.

Program Description:

Here, a class "TextAreaExample" has been defined. This class has main method in which frame and a panel are created and a text area is also created on the panel by using JTextArea class and it's constructor of java.swing package. In the code of the example, constructor of the JTextArea has been used with three arguments. These arguments are as follows:

  • First parameter is string that is for the value of the Text Area component.
  • Second one is a integer value i.e. for the number of rows of the text area component.
  • And last one is also a integer type value that is for number of columns of the Text Area component.

Here is the code of this program:

import javax.swing.*;

public class TextAreaExample {

  public static void main(String[] args){
  JFrame frame= new JFrame("TextArea frame");
  JPanel panel=new JPanel();
  JTextArea jt= new JTextArea("Welcome Roseindia",5,20);
  frame.add(panel);
  panel.add(jt);
  frame.setSize(250,200);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Output this program:

Download this program.

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 22, 2008

Ask Questions?    Discuss: How to Create Text Area In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
RavenX
July 7, 2011
code

how about a text are with scroll bars...
Mohammad Faisal
August 13, 2011
How to fill JFrame with JTextArea?

I want to make an editor like Notepad. So, how can I make JTextArea stick to the JFrame whenever I maximize or restore the frame to a specific height or width?
DMCA.com