- 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
How can I append text to JTextArea in Java?
To append text to JTextArea, use the component’s append() method. Let’sa say the following is our text in the JTextArea -
JTextArea textArea = new JTextArea("The text added here is just for demo. "+ "
This demonstrates the usage of JTextArea in Java. ");
Now, append text to the same textArea -
textArea.append("In this example we have deleted some text from the beginning."+ "
We have also appended some text.");
The following is an example to append text to 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. "); int begn = 0; int end = 10; textArea.replaceRange(null, begn, end); textArea.append("In this example we have deleted some text from the beginning."+ "
We have also appended some text."); 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
- Java Program to paste clipboard text to JTextArea
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- How to display a bold text inside the JTextArea in Java?\n
- Can we select only some of the text in JTextArea?
- How to append text to a text file in C++?
- Java Program to Append Text to an Existing File
- How can we display the line numbers inside a JTextArea in Java?
- How can I append a tuple into another tuple in Python?
- How can we set the orientation of a JTextArea from right to left in Java?
- How to Append Text from One Cell to Another in Excel?
- How can we disable cut, copy and paste functionality of a JTextArea in Java?
- How can I use marquee text in Kotlin?
- How to get the Tab Size of a JTextArea in Java?
- Java Program to display the contents in JTextArea
- Java Program to set JTextArea to wrap by word in Java

Advertisements