aspose file tools*
The moose likes Java in General and the fly likes Highlighting certain strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Highlighting certain strings" Watch "Highlighting certain strings" New topic
Author

Highlighting certain strings

S. Jones
Greenhorn

Joined: Apr 15, 2012
Posts: 4
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
You cannot simply do that in a String, because a String does not have any notion of location. Nor is there any distinction in the String class between "yellow" and "yellow". Even if you have references to different objects both "yellow", the equals() method will not find any discintion between the two.

Back to the old technology, pencil and paper. Write how you are going to do that on paper first. Eraser, too, because you will make mistakes.

You can try writing a class with highlighting, where as well as a String, you have markers for “on” and “off”, possibly stored in a List.

I think this question too difficult for “beginning”, so I shall move it.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Jones, please BeForthrightWhenCrossPostingToOtherSites. You should have at the very least told us here that the question had already been answered elsewhere.
http://www.java-forums.org/new-java/59121-highlighting-certain-strings.html


luck, db
There are no new questions, but there may be new answers.
S. Jones
Greenhorn

Joined: Apr 15, 2012
Posts: 4
Darryl Burke wrote:Jones, please BeForthrightWhenCrossPostingToOtherSites. You should have at the very least told us here that the question had already been answered elsewhere.
http://www.java-forums.org/new-java/59121-highlighting-certain-strings.html

I apologize. I wasn't really aware of that rule. I'll make sure to follow it now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Highlighting certain strings
 
Similar Threads
Highlighting text
Simple STRING Question!
Highlighting Text
how to implement an auto-suggest feature with Struts
How to set multiple fonts inJTextArea or JTextPane