3

How can I show a mathemetical series in a JLabel?

Right now I do it like this by using a String with HTML tags.

String s = "<html>&Sigma;<sup>N</sup><sub>i = 0</sub> x <sub>i</sub></html>";

Result: enter image description here

Is there a nicer way to do this? Because the output is very ugly. Usually N should be above the sigma and i = 0 below.

Steve Benett
  • 12,843
  • 7
  • 59
  • 79

2 Answers2

2

A nicer way to do this is using a third party library to render Latex code in Java.

There are several of them for example JLatexMath, here's a example tutorial.

For instance, using the program of that example your summatory could look like this:

example 1

Or like this:

example 2

DSquare
  • 2,458
  • 17
  • 19
1

Unfortunately I found only the following solution.

String s = "<html><table border='0'><tr>"
            + "<td style='font-size: larger'>&Sigma;</td>"
            + "<td style='font-size: smaller'>N<br>i = 0</td>"
            + "<td> x <sub>i</sub></td>"
            + "</tr></table>"
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138