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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Highlighting Words in a String" Watch "Highlighting Words in a String" New topic
Author

Highlighting Words in a String

Muhammad Ahsan Jamshaid
Ranch Hand

Joined: Jun 01, 2006
Posts: 59
Hi all..
i am making a search function... now i can find the word in a string but i want the finded word to be shown highlighted (in a tree or TextFeild) . Is there any thing that make a String in which some specific words are highlighted or Bold or Color not the whole string... The return type remains a string....

Or any other suggestion to do it......

--Ahsan Jamshaid..


--Ahsan Jamshaid... SCJP 5(80%)
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
Take a look at javax.swing.text.JTextComponent

setSelectionStart(),
setSelectionEnd(), and
setSelectionColor().

You select the text and then change its colour.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Highlighting Words in a String