JavaFX : Put chemical formula into Label

318 views Asked by At

I was wondering if it was possible to put chemical formulas ( SUB and SUP characters) into a Label content like:

enter image description here

1

There are 1 answers

1
Thomas On BEST ANSWER

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));
}