File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Murach's Java Servlets and JSP
this week in the
Swing / AWT / SWT
drawString and exponents
Joined: Apr 09, 2002
Nov 29, 2012 07:25:03
Is there a simple way to use drawString and print out an equation with exponents?
Joined: Apr 09, 2002
Nov 29, 2012 09:18:22
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
AttributedString as1 = new AttributedString("b2 + 14"); as1.addAttribute(TextAttribute.FONT, font); g2d.drawString(as1.getIterator(), 15, 60);
Add a superscript
AttributedString as1 = new AttributedString("b2 + 14"); as1.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 1, 2); g2d.drawString(as1.getIterator(), 15, 60);
This won't do both, will only increase the font.
AttributedString as1 = new AttributedString("b2 + 14"); as1.addAttribute(TextAttribute.FONT, new Font("Verdana", Font.BOLD, 28)); as1.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 1, 2); g2d.drawString(as1.getIterator(), 15, 60);
Joined: Oct 13, 2005
Nov 29, 2012 09:24:08
If you are doing graphics, that might be better discussed in the GUIs forum.
! 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
, and it tells you where to look (\u00b2, I think) for ².
Joined: May 03, 2008
Nov 29, 2012 10:41:20
You could try setting the
attributes instead. My
Visual Font Designer
can help generate the code painlessly. Or maybe using the form of
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.
There are no new questions, but there may be new answers.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
subject: drawString and exponents
Thinking in Java excercise
dividing floating point numbers?
Retrieving Text from drawString()
Java chart printing problems
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014