- 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
Java Program to replace the first 10 characters in JTextArea
To replace the first 10 character in text area, use the replaceRange() method in Java and replace the old text with the new text.
Let’s say the following is oude demo text set with JTextArea −
JTextArea textArea = new JTextArea("This is a text displayed for our example. We have replaced some of the text.");
Now, replace the characters in a range −
int begn = 0; int end = 10; // replace textArea.replaceRange("Replaced! ", begn, end);
The following is an example to replace the first 10 charactrers in JTextArea −
Example
package my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame("Demo"); JTextArea textArea = new JTextArea("This is a text displayed for our example. We have replaced some of the text."); int begn = 0; int end = 10; // replace textArea.replaceRange("Replaced! ", begn, 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 (); } }
Output
- Related Articles
- Delete the first 10 characters from JTextArea in Java
- Java Program to display the contents in JTextArea
- Java Program to set JTextArea to wrap by word in Java
- How to replace characters on String in Java?
- Java Program to paste clipboard text to JTextArea
- Java program to swap first and last characters of words in a sentence
- How to find the first 10 characters of a string in C#?
- Program to replace all digits with characters using Python
- Java program to Find the first non-repeating character from a stream of characters
- Java Program to replace only first occurrences of given String with new one
- Program to replace all the characters in of a file with '#' except a particular word in Java
- Replace first occurrence of a character in Java
- Program to get JTextArea font information
- Program to replace all question symbols to avoid consecutive repeating characters in Python
- Python program to replace first ‘K’ elements by ‘N’

Advertisements