Just wanted to add to what @aioobe mentioned above ...
In this approach, you use HTML to color code your text. Although this is one of the most commonly used ways of coloring code for label text, it is not the most efficient way to do it .... given the fact that each label will lead to analysis, rendering, etc. If you have large forms of the user interface to be displayed, every millisecond expects to give a good user interface.
You might want to go through below and try.
Jide OSS (located at https://jide-oss.dev.java.net/ ) is a professional open source library with a really good amount of Swing components ready to use. They have a significantly improved version of JLabel called StyledLabel. This component solves your problem perfectly ... See if their open source licensing applies to your product or not.
This component is very easy to use. If you want to see a demo of your Swing Components, you can run their WebStart demo located at www.jidesoft.com ( http://www.jidesoft.com/products/1.4/jide_demo.jnlp ). All of their suggestions are demos ... and best of all, StyledLabel compares to JLabel (HTML and without) in terms of speed !:-)
A screenshot of the performance can be seen at ( http://img267.imageshack.us/img267/9113/styledlabelperformance.png )
arcamax Jun 03 '10 at 16:03 2010-06-03 16:03
source share