Displaying Fancy Equations with Java

Displaying fancy equations with Java

I know these libraries for Java:

  • JEuclid (MathML renderer; Apache License)

  • JLatexMath (Latex renderer; GNU License) improved JMathTeX

  • JMathTeX (Latex renderer; GNU License)

  • HotEqn (Latex renderer; GNU License ?)

  • SnuggleTex (Latex renderer; BSD License)

For the animation part of your question, you can look at these projects:

  • DragMath equation editor (Swing interface; GNU License)

  • Mirai Calc calculator (SWT interface; GNU License; uses JMathTeX)

  • Java Swing Equation builder

For a web interface you can also use the jsMath JavaScript or it's successor Mathjax library as a Latex/MathML renderer.

display math equation in java using jlabel

You don't need any library, you can format the String as HTML and display it.

For example, if you want to display ax^2+10x=15 on the jbSolution button, you should do like this:

    int a=5, b=10, c=15;

String j = "<html>"+a+"x<sup>2</sup>+"+b+" x = "+c+"</html>";
jbSolution =new JButton(j);
jbSolution.setBounds(20,150,130,30);

For D=b^2-4ac

String j = "<html>D = b<sup>2</sup> -  4ac</html>";

For beta=(-b-root(D)/2a

String j = "<html>beta=(-b-\u221AD)/2a</html>";

Display Math Formula in javaFX

Since JLaTeXMath is using the Graphics2D API for rendering, you can use FXGraphics2D to draw the output to a JavaFX Canvas. For sample code, please refer to my answer to another similar question https://stackoverflow.com/a/25037747/2592874

Showing a mathematical series in JLabel

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

JavaFX : Put chemical formula into Label

Here a solution using jlatexmath:

private void createGraphic(String textValue, Color color) {
TeXFormula tex = new TeXFormula(textValue);
java.awt.Image awtImage = tex.createBufferedImage(TeXConstants.STYLE_TEXT, 12, color, null);
Image fxImage = SwingFXUtils.toFXImage((BufferedImage) awtImage, null);
label.setGraphic(new ImageView(fxImage));
}


Related Topics



Leave a reply



Submit