I am writing a text editor(in java) where I am using a JTextArea for the main text editing and I am putting the text into a stringbuilder.
When I highlight the text and do something like delete that block of text, I want it to update in the stringbuilder.
So my question is, is there a way to get the first and last index of the highlighted text in the stringbuilder?
Thanks.
You can keep them in sync using a
DocumentListeneras below. However, I heavily recommend rethinking whatever approach you’re trying to take here. It seems like you’re trying to use an external StringBuilder as the “model” to your JTextArea, but the Document is the model. So I fail to see when this would be a good idea.