Consider using a JEditorPane [1] to display an HTMLDocument [2].
JTextComponents, like JEditorPane, have methods to obtain the
selection start and end, which may be of use. You might look at the Sun
tutorial on "Using Text Components" [3] and "How to Use Editor Panes
and Text Panes" [4].
[1]<http://java.sun.com/javase/6/docs/api/javax/swing/JEditorPane.html>
[2]<http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTMLDocument.html>
[3]<http://java.sun.com/docs/books/tutorial/uiswing/components/text.html>
[4]<http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Marking text with a CSS class will insist you insert your markers in a
balanced way, so you would have to mark a arbitrary string with a
number of sub pieces.
If you rendered your own HTML, you could do what you wanted, but then
your browser will not be tolerant to erroneous HTML or new syntax.
If you somehow ran a browser in the background, you might be able to
capture its output and repaint it with your decorations. This is the
approach I think would have most chance of success.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Without deviation from the norm, progress is not possible.
~ Frank Zappa (born: 1940-12-21 died: 1993-12-04 at age: 52)