java - Formatting Text in JLabel, specifically scientific/mathematical units -



java - Formatting Text in JLabel, specifically scientific/mathematical units -

this isn't overly critical question , marked duplicate since inquire has sort of been asked before( not using same characters trying do, , asked around 2011 - 2012, maybe there different answers now).

ok, have have physics programme writing requires numerical input, values of constants, etc.... using jlabels of jtextfield labels. understand using html tagging super , subscript when trying create fractions. physics units not numerical fractions (i.e. meters per sec squared). below have done seek create this, , moderately successful (does job pretty ugly).

import java.awt.borderlayout; import java.awt.color; import java.awt.eventqueue; import javax.swing.borderfactory; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; public class mathformattingtest extends jframe { private static final long serialversionuid = 1l; jpanel panel; jlabel gravitationalaccelerationconstantlabel; jlabel densityofpvcconstantlabel; private void initcomponents() { panel = new jpanel(); gravitationalaccelerationconstantlabel = new jlabel(); densityofpvcconstantlabel = new jlabel(); setdefaultcloseoperation(exit_on_close); borderlayout layout = new borderlayout(25, 25); panel.setlayout(layout); panel.setbackground(color.white); panel.setopaque(true); panel.setborder(borderfactory.createemptyborder(25, 25, 25, 25)); gravitationalaccelerationconstantlabel.settext("<html>gravitational acceleration (<sup>m</sup> &#8260 <sub>s<sup> 2 </sup></sub>): 9.81</html>"); densityofpvcconstantlabel.settext("<html>density of pvc (<sup>lb</sup> &#8260 <sub>in</sub>): 0.04225</html>"); panel.add(gravitationalaccelerationconstantlabel, borderlayout.north); panel.add(densityofpvcconstantlabel, borderlayout.south); add(panel); pack(); setlocationrelativeto(null); } public mathformattingtest() { initcomponents(); } public static void main(string[] args) { eventqueue.invokelater(new runnable() { @override public void run() { new mathformattingtest().setvisible(true); } }); } }

if compile , run programme see output isn't cleanest thing in world. 1 thing suggested draw paint component convert image icon , post icon. seems lot of effort think relatively simple. maybe crazy think relatively commonplace in java programming , there "prettier" way of doing it. suggestions guys can give more welcome, place never lets me downwards , should go-to trying larn programming.

java html swing unicode jlabel

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -