Start with methods of JTextArea:
- see the
getLineStartOffset(...)
andgetLineEndOffset(...)
methods. - then you can use the
getText(...)
method to get all the text for the line. - then you can use
String.indexOf(...)
to search the text for the location of "first". - now you can add the offset from the start of the line and the indexOf methods to get the location of the text you want to highlight in the document
- then you can use the
getHighlighter()
method of the text area to get the highlighter - finally you can use the
addHighlight()
method to highlight the word