| Author |
Super and sub string in java to string
|
Laxmikant Kumbhare
Ranch Hand
Joined: Sep 19, 2011
Posts: 38
|
|
I need to set sub script in java string !
Please any one help me!
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
|
I fear there is one like setting a Subscript or Supersript in the String class. Can you elaborate more on your purpose? Do you want to show like that in a UI?
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5855
|
|
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.
|
 |
Laxmikant Kumbhare
Ranch Hand
Joined: Sep 19, 2011
Posts: 38
|
|
YES, exactly! I want to display a subscripted string on UI......................../././././././.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32668
|
|
You can have html tags on some Components, I think a JLabel, but I am not certain. Then you could write <sub>some text</sub> or similar.
I think that would be better discussed on the GUIs forum: moving thread.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
<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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Laxmikant Kumbhare
Ranch Hand
Joined: Sep 19, 2011
Posts: 38
|
|
|
Thanks a lot rob! I will use it.......
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You're welcome.
|
 |
Laxmikant Kumbhare
Ranch Hand
Joined: Sep 19, 2011
Posts: 38
|
|
|
thank you! I will post if I need some help
|
 |
 |
|
|
subject: Super and sub string in java to string
|
|
|