TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Swing

Create Text Area using JTextArea Class

Overview

In this tutorial, we will learn steps to create a text area using JTextArea class. Text Area is a GUI component that allows users to input multiple lines of text.

JTextArea Class

To create a text area, we can use the JTextArea class. To import the class we can use the following import statement:

import javax.swing.JTextArea;

The display area of JTextArea is defined by rows and columns properties.

JTextArea ta = new JTextArea(10, 10);

Java Program

package com.testingdocs.swing.components;

/**********************************************
 * FileName: JTextAreaDemo.java
 * Package : com.testingdocs.swing.components
 * 
 * Java Tutorials - www.TestingDocs.com
 **********************************************/

import java.awt.*;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class JTextAreaDemo {

 public static void main(String[] args) {
 final JFrame frame = new JFrame("JTextArea -www.TestingDocs.com");
 JTextArea tArea = new JTextArea(20, 30);
 JScrollPane sp = new JScrollPane(tArea);
 tArea.setText("Sample Text in Text Area...."); 
 frame.setLayout(new FlowLayout());
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setSize(400, 400);
 frame.getContentPane().add(sp);
 frame.setVisible(true);
 }
}

Output

Run the program to view the output.

JTextArea Class

—

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Add GUI Components Swing

Java Swing /

Add GUI Components to a Swing Container

JPanel Container Class

Java Swing /

Swing JPanel Container Class

Swing CardLayout

Java Swing /

Java Swing CardLayout

Java Swing GridLayout

Java Swing /

Java Swing GridLayout

Java Swing FlowLayout

Java Swing /

Java Swing FlowLayout

‹ Create Text Field using JTextField› Create ComboBox using JComboBox Class

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com