File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes drawString and exponents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "drawString and exponents" Watch "drawString and exponents" New topic
Forums: Swing / AWT / SWT Beginning Java

drawString and exponents

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
Is there a simple way to use drawString and print out an equation with exponents?
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
OK. So I can achieve superscript and I can achieve making font larger but it seems that I cannot do both at the same time. Any suggestions on achieving both?
Make font larger

Add a superscript

This won't do both, will only increase the font.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45251
If you are doing graphics, that might be better discussed in the GUIs forum. Nil desperandum! I can copy this discussion so it is in both fora

Are you aware of superscript characters? You can probably use \u2074 and get ⁴. More details here, and it tells you where to look (\u00b2, I think) for ².
Darryl Burke

Joined: May 03, 2008
Posts: 5090

You could try setting the Font attributes instead. My Visual Font Designer can help generate the code painlessly. Or maybe using the form of AttributedString#addAttribute(...) that takes a Map would produce the desired result.

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates your problem.

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: drawString and exponents
It's not a secret anymore!