I am searching for a field in the text area on the clicking of a button and wants to highlight it .When i am searching for the field i am only able to highlight the first existence of the field but i want to highlight all the existence of that field in text area at one go . Please help
Rob Prime wrote:http://faq.javaranch.com/java/EaseUp
You can find the first occurrance, then just search again from that point on for the next one. String has indexOf methods that take a starting index.
that i tried but the problem here is that i am not able to start the search from the index where i first found that word. It is starting from the start of the text area .I tried it by creating some global variable where i can retain that but it is still not happening .
The usual way to search a string over and over:
Joined: Mar 05, 2009
Rob Prime wrote:The usual way to search a string over and over:
Thanks for your reply Rob but the thing here is that i am noot able to understand how the code you had written will work it can only provide me with the first occurance of the string .But the outher ocurrance of the same string i am not able to get
Correct. I (falsely) assumed that Mayank already was using a Highlighter.
To highlight, you need a DefaultHighLighter, then use its addHighlight method with a DefaultHighlighter.DefaultHighlightPainter. You can of course use other implementations of both Highlighter and Highlighter.HighlightPainter but these two implementations should already work for you.