How to add superscript to Label text in Javafx 8

时间秒杀一切 提交于 2019-12-06 07:43:25

问题


I am writing my first JavaFX application and I cannot find how to make some of the text in a Label to be superscript.

In Swing it was easy enough to use HTML tags, but this option is not available in JavaFX.

I have searched through many of the api's including Label, Font, TextFlow, Oracle docs and samples, and the internet in general.

Thank you.


回答1:


The WebView is more flexible, but, depending upon which font you are using and the content of the superscript, there are Unicode superscript characters such as U+00B2 for the superscript 2.




回答2:


One approach would be to substitute a WebView and use the loadContent() method of WebEngine.

WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
webEngine.loadContent(
    "<h1>G<sub>&mu;&nu;</sub>=8πT<sub>&mu;&nu;</sub>; E=mc<sup>2</sup>");



来源:https://stackoverflow.com/questions/31716969/how-to-add-superscript-to-label-text-in-javafx-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!