- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Delete the first 10 characters from JTextArea in Java
Let’s say the following is our JTextArea with default text −
JTextArea textArea = new JTextArea("The text added here is just for demo. " + "
This demonstrates the usage of JTextArea in Java. In this example we have" + "deleted some text.");
Now to remove the first 10 characters, use replaceRange() method and set null from one end to another i.e. deleting characters in a range. The replaceRaneg() method Replaces text from the indicated start to end position with the new text specified i.e.e here null will replace the first 10 characters −
int start = 0; int end = 10; textArea.replaceRange(null, start, end);
The following is an example to delete the first 10 characters from JTextArea −
Example
package my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame("Demo"); JTextArea textArea = new JTextArea("The text added here is just for demo. " + "
This demonstrates the usage of JTextArea in Java. In this example we have" + "deleted some text."); int start = 0; int end = 10; textArea.replaceRange(null, start, end); frame.add(textArea); frame.setSize(550,300); frame.setLayout(new GridLayout(2, 2)); frame.setVisible(true); } public static void main(String args[]) { new SwingDemo (); } }
The output is as follows. We have deleted first 10 characters here −
Output
- Related Articles
- Java Program to replace the first 10 characters in JTextArea
- Java program to delete duplicate characters from a given String
- Delete first and last element from a LinkedList in Java
- MySQL query to keep only first 2 characters in column value and delete rest of the characters?
- How to extract the first n characters from a string using Java?
- Delete a collection from MongoDB with special characters?
- How to find the first 10 characters of a string in C#?
- Java Program to display the contents in JTextArea
- Removing first k characters from string in JavaScript
- Java program to Find the first non-repeating character from a stream of characters
- How to select all the characters after the first 20 characters from a column in MySQL?
- JavaScript - Remove first n characters from string
- How can we set the orientation of a JTextArea from right to left in Java?
- What are the differences between JTextField and JTextArea in Java?
- Golang Program to delete the first node from a linked list.

Advertisements