Does Java String supports superscript in a String? If yes then how can I use it, I have searched the web and also the API but not able to figure out how I can use it for my
Here is the example how to superscript the string "JavaTM" in Java.
in as1.addAttribute method
'4' is the beginIndex Index of the first character and '6' is the endIndex Index of the character for superscript.
Example:
public class TextAttributesSuperscript extends JPanel {
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
AttributedString as1 = new AttributedString("JavaTM");
as1.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 4, 6);
g2d.drawString(as1.getIterator(), 15, 60);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Java Superscript Example");
frame.add(new TextAttributesSuperscript());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(320, 190);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Output of this program: