Display Math Formula in javaFX


Question

I want to know how to display math formula in a label for exemple in JavaFX. Like this picture : Sample formula I want the .jar of a library and a small example in JavaFX. I already found some libraries but they are only for Swing/AWT. I tried some of them, but they don't work for me.

Displaying fancy equations with Java

1
2
5/23/2017 12:26:05 PM

Accepted Answer

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

5
5/23/2017 12:18:04 PM

Just a copy from my answer to https://stackoverflow.com/a/25037747/2592874

The next coming versions of JavaFX support MathML :

  • JavaFX 8 Update 192 included in Java 8 Update 192
  • JavaFX 11.

Just use a WebView control and MathML and set HTML Content with :

<math display="block"> 
   <mrow> 
      <mi>x</mi> 
      <mo>=</mo> 
      <mfrac> 
         <mrow> 
            <mo>−</mo> 
            <mi>b </mi> 
            <mo>±</mo> 
            <msqrt> 
               <mrow> 
                  <msup> 
                     <mi>b</mi> 
                     <mn>2</mn> 
                  </msup> 
                  <mo>−</mo> 
                  <mn>4</mn> 
                  <mi>a</mi> 
                  <mi>c</mi> 
               </mrow> 
            </msqrt> 
         </mrow> 
         <mrow> 
            <mn>2</mn> 
            <mi>a</mi> 
         </mrow> 
      </mfrac> 
   </mrow>
</math>

Follow the link JavaFX / OpenJFX Download to reach JavaFX version 11 and beyond. Follow the link Java Early Access Download to reach the early access to these versions.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon