Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By DarrylBurke

Thread: HIGHLIGHTING certain strings

  1. #1
    onions is offline Member
    Join Date
    Apr 2012
    Posts
    9
    Rep Power
    0

    Default HIGHLIGHTING certain strings

    Hi, so I have text in my JTextArea. A method is called to break up that text into sentences stored in an ArrayList. It is necessary for this to happen so I can find certain strings within the sentence.
    So right now i have the original in the JTextArea and a copy broken up into sentences in an ArrayList.

    My Goal is to highlight the string I found (in the ArrayList through other methods), but only in the place where i found it in the sentence.
    ex.) "The yellow pineapple is yellow." Lets say the string I found (in the ArrayList) was the last "yellow" in the sentence.

    My Problem is How can i find that exact same "yellow" in the original text and highlight it?

    This has really been messing me up so any insight would be really helpful and appreciated. Thank you.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: HIGHLIGHTING certain strings

    I would suggest using a data structure more suited to the task. For example, with a LinkedHashMap<String, Integer> you could store the starting index of each sentence and use that index along with the index of the word within the sentence to locate the word in the JTextArea.

    Watch out for newlines if your text may contain them. See camickr's Text and New Lines Java Tips Weblog

    db
    k1ng and onions like this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    onions is offline Member
    Join Date
    Apr 2012
    Posts
    9
    Rep Power
    0

    Default Re: HIGHLIGHTING certain strings

    Quote Originally Posted by DarrylBurke View Post
    I would suggest using a data structure more suited to the task. For example, with a LinkedHashMap<String, Integer> you could store the starting index of each sentence and use that index along with the index of the word within the sentence to locate the word in the JTextArea.

    Watch out for newlines if your text may contain them. See camickr's Text and New Lines Java Tips Weblog

    db
    Thanks for the reply! Its a good idea for finding the index. I'll try it out :)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: HIGHLIGHTING certain strings

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Search Result and Highlighting
    By sprateek in forum Lucene
    Replies: 0
    Last Post: 10-08-2011, 01:50 PM
  2. Highlighting line in JTextArea
    By misiom1 in forum New To Java
    Replies: 4
    Last Post: 01-15-2011, 01:39 PM
  3. JTree setSelectionPath not highlighting
    By PrinceSendai in forum AWT / Swing
    Replies: 2
    Last Post: 12-22-2010, 05:34 AM
  4. Eclipse Syntax Highlighting
    By garrettgjb in forum Eclipse
    Replies: 1
    Last Post: 08-24-2009, 03:10 PM
  5. [SOLVED] Line Highlighting
    By Doctor Cactus in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 03:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •