views:

194

answers:

4

Hi i'm looking for a way to highlight specific words in text kind of like how a text editor might work with syntax highlighting. The highlighting will consist of the text being different colours and/or different styles such as italic, bold or regular.

In order to narrow focus, how this might be achieved using Java Swing components.

There are most probably a number of ways of doing this but one that is efficient in dealing with multiple highlighted words and large amounts of text.

Any feedback is appreciated. Thanks.

+2  A: 

Have a look at Java's JEditorPane class: it does what you want.

Bart Kiers
thank you for the reply
Uncle
+1  A: 

You can use the Highlighter that is available through JTextComponent's setHighlighter().

Sayornis
+1  A: 

I would use a JTextPane. Its easier to use than a JEditorPane as you don't have to know or worry about HTML. The link you where given to the Swing tutorial covers both components.

camickr