Hi, Is there a way in Java so that we can display superscript and subscript characters like in a chemical formula Ex. CO2,H2O the character 2 should be displayed as a subscript. I want to display formula as JLabel in my application.In some formulae I may have to display square of a number.....so I need to know how to display characters in superscript also.
Any suggestions are welcome. Thanks Pomchi [ January 18, 2002: Message edited by: Pomchi Bedi ]
Hi bedi , you can use TFormula class for displaying chemical formulae. The corresponding API says ------> TFormula provides a simple mechanism for displaying Chemical Formulae. By default this puts all numbers as subscripts, thus formula can be entered in the form "CH3CH2OH". However the autoscripting option can be turned off, thus formulae should be input in the following form "CH3CH2OH" . (actually here 3 and 2 are subscripts..but i m not able to write them as subscripts :-)) If u have any doubts,just check the API Documentation. Cheers, Srikanth [ January 20, 2002: Message edited by: s srikanth ]
posted 17 years ago
Hi Srikanth, Thanks for your reply.I could not find TFormula in the jdk1.2.2 api documentation....can you please tell me the name of the Package it belongs to.Also could you please tell me the version of the api I should look in. Thanks Pomchi
Yes, one of my personal pet peeves is someone mentioning a class out of a non-standard API and not giving a reference to the package that provides it. However, when not finding the class in the standard APIs, my next source of data is an Internet search engine (like google) and searching for the name of the class, or sometimes the name of the class and "Java" if it is a pretty common name. I found the site ChemSymphony by searching for "TFormula Java", and it claims to provide "a components tool kit for chemistry applications" of the same name... looking at the docs on the site it has a TFormula class that looks like the one Srikanth is talking about... however, it also looks like you have to pay to license ChemSymphony (though they do provide a Lite version for download... don't know if TFormula comes in that...)
If you can't use TFormula from ChemSymphony, it would be pretty simple to make a component to display formulas by overriding the paintComponent() method and adding a StringTokenizer to figure out what size to draw different parts of the String.