Selection

JTextComponent c = new JTextArea();

// Get text inside selection
c.getSelectedText();

// Replace selected text
c.replace("replacement text");

// Set the start of the selection; ignored if new start is < end
c.setStart(10);

// Set the end of the selection; ignored if new end is > start
c.setEnd(20);

// Better way to set the selection
c.select(10, 20);

// Set the color of text inside the selection
c.setSelectedTextColor(Color.red);

// Set the color behind the selected text
c.setColor(Color.green);

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.