October 22nd, 2013, 06:58 AM
Highlighting the patterns in the text
I am working with strings.I have used apache poi 3.9 My program is matching a pattern in the string and then it gives the results in the form of highlighted text in the string to let the user know this pattern is found on this location in the string. The result file will be word document containing the string along with the highlighted portion. I have matched the patterns in the string and stored them in the array. But I am still at lost as to how shall I highlight the text. And there is problem also that matched patterns are in the array and each still be highlighted with different color which I do not know how to do.
This is my code for identifying patterns.
Pattern p = Pattern.compile( strArray[j] );
while(m.find())//finding pattern in the sequence
patArray[inpat]=m.group();// stored match pattern in another array
Please let me know or give me suggestion as to how I shall I highlight my patterns in the string.
October 22nd, 2013, 07:26 AM
How is the text being shown to the user? The JTextPane class will honor HMTL tags that can wrap the text.
October 22nd, 2013, 08:12 AM
The result will be in the form of string which will have highlighted portion indicating that pattern are found on that location. And the file will be word document.
October 22nd, 2013, 08:19 AM
If the place the String is shown is in a word document, then you need to ask the question on a forum for how to write a word document file.