Java Swing How to - Insert Text in a JTextArea








Question

We would like to know how to insert Text in a JTextArea.

Answer

/*from   ww w .  j  av  a  2 s . c o  m*/


import javax.swing.JTextArea;

public class Main {
  public static void main(String[] argv) {

    // Create the text area
    JTextArea ta = new JTextArea("Initial Text");

    // Insert some text at the beginning
    int pos = 0;
    ta.insert("some text", pos);

  }
}