This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Super and sub string in java to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Super and sub string in java to string" Watch "Super and sub string in java to string" New topic
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: 1776
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: 6109
    
    6

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: 39478
    
  28
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: 19723
    
  20

<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 - OCEEJBD 6
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: 19723
    
  20

You're welcome.
Laxmikant Kumbhare
Ranch Hand

Joined: Sep 19, 2011
Posts: 38
thank you! I will post if I need some help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Super and sub string in java to string