JTextArea Append - Java Swing

Java examples for Swing:JTextArea

Description

JTextArea Append

Demo Code


//package com.java2s;

import javax.swing.JTextArea;

public class Main {
    public static void areaAppend(JTextArea area, String text) {
        if (area != null) {
            if (area.getText().trim().length() != 0) {
                area.append("\r\n");
            }//from  w  w w  .j a  va 2s.  c  om
            area.append(text);
            int l = area.getDocument().getLength();
            if (text.length() < l)
                l = l - text.length();
            area.setCaretPosition(l);
        }
    }
}

Related Tutorials