Editing text in a JTextArea


This example shows how you can edit the text inside the JTextArea.

// Create the text area
JTextArea ta = new JTextArea("Initial Text");

// Insert some text at the beginning
int pos = 0;
ta.insert("some text", pos);

// Insert some text after the 5th character
pos = 5;
ta.insert("some text", pos);

// Append some text
ta.append("some text");

// Replace the first 3 characters with some text
int start = 0;
int end = 3;
ta.replaceRange("new text", start, end);

// Delete the first 5 characters
start = 0;
end = 5;
ta.replaceRange(null, start, end);


One thought on “Editing text in a JTextArea”

  1. This website is known as a walk-by means of for the entire data you wished about this and didn抰 know who to ask. Glimpse right here, and you抣l undoubtedly discover it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.