Delete the first 5 characters from JTextArea in Java
Description
The following code shows how to delete the first 5 characters from JTextArea.
Example
import java.awt.Font;
//from w w w .j a v a 2 s .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);
int start = 0;
int end = 5;
textArea.replaceRange(null, start, end);
}
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 »