Replace the first 3 characters with some text in Java
Description
The following code shows how to replace the first 3 characters with some text.
Example
import java.awt.Font;
/*from w w w . jav a 2 s. co m*/
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);
int start = 0;
int end = 3;
textArea.replaceRange("java2s.com", start, end);
}
public static void main(String[] args) {
JFrame frame = new Main();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}