#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Lightbulb 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.
    Java Code:
    Code:
    for(int j=0;j<numRows;j++)
            {
     
       Pattern p = Pattern.compile( strArray[j] );
       m=p.matcher(str);
       while(m.find())//finding pattern in the sequence
     
       {
        patArray[inpat]=m.group();// stored match pattern in another array
        inpat++;
        System.out.println(m.group());
     
    }
       }
    This is my code for identifying patterns.

    Please let me know or give me suggestion as to how I shall I highlight my patterns in the string.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    how shall I highlight the text
    How is the text being shown to the user? The JTextPane class will honor HMTL tags that can wrap the text.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0
    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.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    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.

IMN logo majestic logo threadwatch logo seochat tools logo