Display Math Formula in javaFX

梦想与她 提交于 2019-12-06 04:35:33

问题


I want to know how to display math formula in a label for exemple in JavaFX. Like this picture :

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:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/24973389/display-math-formula-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!