How do I create an uneditable JTextArea?

The following example shows you how to set the property of the JTextArea so that it cannot be edited or modified. To make the JTextArea not editable call the setEditable() method and pass a false value as the parameter.

package org.kodejava.example.swing;

import javax.swing.*;
import java.awt.*;

public class TextAreaNotEditable extends JPanel {
    public TextAreaNotEditable() {

    private void initializeUI() {
        this.setLayout(new BorderLayout());
        this.setPreferredSize(new Dimension(500, 200));

        JTextArea textArea = new JTextArea(5, 50);
        textArea.setText("The quick brown fox jumps over the lazy dog.");

        // By default the JTextArea is editable, calling
        // setEditable(false) produce uneditable JTextArea.
        JScrollPane scrollPane = new JScrollPane(textArea);

        this.add(scrollPane, BorderLayout.CENTER);

    public static void showFrame() {
        JPanel panel = new TextAreaNotEditable();

        JFrame frame = new JFrame("JTextArea Demo");

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

The output of the code snippet is:

Uneditable JTextArea Demo

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you ?


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.