This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Laxmikant Kumbhare wrote:I need to set sub script in java string !
Not possible. A String is just a sequence of character. It has no concept of font or style or any such thing. What you probably mean is that you want the display of some String in a GUI to be subscripted. If you can confirm that, and clarify your context a bit, somebody can help you.
Joined: Sep 19, 2011
YES, exactly! I want to display a subscripted string on UI......................../././././././.
<sup> and <sub> are part of HTML3.2 and so there should be support for it in Swing. Create a JLabel and set its text to the HTML you want; it needs to start with <html>, and can then contain all the bold, underline, italic, superscript and subscript tags you want. For instance:
To specify superscript or subscript for an entire font that's also possible:
TextAttribute.SUPERSCRIPT_SUPER is an Integer with value 1; TextAttribute.SUPERSCRIPT_SUB is an Integer with value -1. You can use any value between -7 and 7 (inclusive) to increase the superscript / subscript level.