Insert Text to JTextArea in Java
Description
The following code shows how to insert Text to JTextArea.
Example
//from w ww. ja va2 s . co m
import java.awt.Font;
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);
// Insert some text at the beginning
int pos = 0;
textArea.insert("java2s.com", pos);
}
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.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »