Append some text to JTextArea in Java

Description

The following code shows how to append some text to JTextArea.

Example


import java.awt.Font;
/*from   ww  w.  j av  a 2s  . c om*/
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Main extends JFrame {

  public Main() {
    JTextArea textArea = new JTextArea("Initial Text");
    textArea.setFont(new Font("LucidaSans", Font.PLAIN, 40));
    add(textArea);    

    textArea.append("java2s.com");
  }

  public static void main(String[] args) {
    JFrame frame = new Main();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
    frame.setVisible(true);
  }
}

The code above generates the following result.

Append some text to JTextArea in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer