HIGHLIGHTING certain strings
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.
Re: HIGHLIGHTING certain strings
I would suggest using a data structure more suited to the task. For example, with a LinkedHashMap<String, Integer> you could store the starting index of each sentence and use that index along with the index of the word within the sentence to locate the word in the JTextArea.
Watch out for newlines if your text may contain them. See camickr's Text and New Lines « Java Tips Weblog
db
Re: HIGHLIGHTING certain strings
Quote:
Originally Posted by
DarrylBurke
I would suggest using a data structure more suited to the task. For example, with a LinkedHashMap<String, Integer> you could store the starting index of each sentence and use that index along with the index of the word within the sentence to locate the word in the JTextArea.
Watch out for newlines if your text may contain them. See camickr's
Text and New Lines « Java Tips Weblog
db
Thanks for the reply! Its a good idea for finding the index. I'll try it out :)
Re: HIGHLIGHTING certain strings