Java : getting the proper StartOffset for multiple text color in JTextPane

oMaRcO

New Member
I need to create a program that accepts a string input and will highlight certain words that is in my String List.Example:\[code\]String MyList[] = {"Dog","Cat","Lion"};Sample Input Text: I have a Dog and a Cat and a Lion . "\[/code\]I dont have problem if the input text doesn't have any new line or escape character but if the input text have new line, this is the result.Example:\[code\]String MyList[] = {"Dog","Cat","Lion"}; \[/code\]Sample Input Text:\[code\]I have a Dog and a Catand a Lion\[/code\]Note: The uppercase character means highligthed character\[code\]I have a DOGand a cATand a liON\[/code\]My Sample Code for Highlighting:\[code\]for(String x : MyList){int startOffset = inputText.indexOf(x);doc.setCharacterAttributes (startOffset,x.length,myStyle,false);}\[/code\]I guess the problem is the Newline or escape character but I can't find a way to fix it.How can I get the correct start offset of the word if ever the input string have new line/s?Any Idea?
 
Top