Display Math Formula in javaFX

2019-04-12 16:15发布

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

3条回答
仙女界的扛把子
2楼-- · 2019-04-12 16:36

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

查看更多
别忘想泡老子
3楼-- · 2019-04-12 16:38

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.

查看更多
ら.Afraid
4楼-- · 2019-04-12 16:45

I looked at JLatexMath, mentioned in your referenced answer, and it can genereate a BufferedImage. With SwingFXUtils you can convert it to a JavaFX Image and use it in your application.

The same approach might work for one of the other libraries.

查看更多
登录 后发表回答