Java String中的上标 [英] superscript in Java String

查看:936
本文介绍了Java String中的上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java String是否支持String中的上标?如果是,那么我该如何使用它,我已经搜索了网络和API,但无法弄清楚如何将它用于我的目的

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 purpose

虽然这样会打印在网页上,我不能在这里使用html标签,请提出任何建议

Although this will be printed on the webpage, I cannot use the html tag here, any suggestions please

推荐答案

查看java.text.AttributedString,它支持下标等。例如,在你的paintComponent()中你可以去:

Check out java.text.AttributedString, which supports subscripts and more. e.g., in your paintComponent() you could go:

   public void paintComponent(Graphics g) {
      super.paintComponent(g);
      AttributedString as = new AttributedString("I love you 104 gazillion");
      as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 13, 14);
      as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 2, 6);
      g.drawString(as.getIterator(), 20, 20);
   }

这篇关于Java String中的上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆