Hi, so I have text in my JTextArea. A method is called to break up that text into sentences stored in an ArrayList. It is necessary for this to happen so I can find certain strings within the sentence.
So right now i have the original in the JTextArea and a copy broken up into sentences in an ArrayList.
My Goal is to highlight the string I found (in the ArrayList through other methods), but only in the place where i found it in the sentence.
ex.) "The yellow pineapple is yellow." Lets say the string I found (in the ArrayList) was the last "yellow" in the sentence.
My Problem is How can i find that exact same "yellow" in the original text and highlight it?
This has really been messing me up so any insight would be really helpful and appreciated. Thank you.
You cannot simply do that in a String, because a String does not have any notion of location. Nor is there any distinction in the String class between "yellow" and "yellow". Even if you have references to different objects both "yellow", the equals() method will not find any discintion between the two.
Back to the old technology, pencil and paper. Write how you are going to do that on paper first. Eraser, too, because you will make mistakes.
You can try writing a class with highlighting, where as well as a String, you have markers for “on” and “off”, possibly stored in a List.
I think this question too difficult for “beginning”, so I shall move it.