I am working on simple text editor, which functionality also includes Highlighting searched text. Here is situation: User loads text file into JTextPane. Then it selects Text Search tool and enters text to be searched. It confirms text search function with pressing "Mark All" button, which highlights all searched hits in text. But here is the problem - here is my code:

In the first method, I gather start and end indexes of matched words in string, represented in JTextPane. The second method colorMathces highlights words, that are available in list of hits (parameter final ArrayList<CTextIndex>). The highlightaion shows, but in the wrong words. Why? I attached screenshot for windows file hosts and search parameter "127":Attachment 3397How do I translate string index to JTextPane coordinate?