Another option is to use unicode symbols encoded in the String with the syntax \uCODE, replacing CODE with desired unicode code. For example, the subscript 2 is represented as \u2082
So, H20 would become "H\u2082O" if you replace the 2 in the String "H2O".
This solution has a better performance than the one using html tags in Swing components (as <sub>2</sub>) because it doesn't require HTML rendering.
In this page http://theorem.ca/~mvcorks/cgi-bin/unicode.pl.cgi?start=2070&end=209F" you can find other subscript and superscript unicode codes.
Edited by: oleguer on Nov 5, 2007 3:48 AM