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:
Or like this:
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
Log4J2 - Assigning File Appender Filename at Runtime
How to Pass C Structs Back and Forth to Java Code in Jni
Are There Any Other Java Libraries for Bonjour/Zeroconf Apart from Jmdns
What Is the Equivalent of Java Static Final Fields in Kotlin
How to Add Test Coverage to a Private Constructor
Java Benchmarking - Why Is the Second Loop Faster
Can Add Extra Field(S) to @Manytomany Hibernate Extra Table
How to Compile Java to Native Code
Hibernate - Foreign Keys Instead of Entities
Generate JPA 2 Entities from Existing Database
Close One Jframe Without Closing Another
How to Compile Multiple Java Source Files in Command Line
Lists with Wildcards Cause Generic Voodoo Error
In Java, How to Define an Integer Constant in Binary Format