5 thoughts on “JavaFX : How to add an image to HTMLEditor

  1. thanks this has worked for me.
    Also, if you want to append a local image, instead of setting source to image data, set it to an absolute URI. Assuming the image is referenced by a variable called “File imageFile”:

    String img = “;

    btn.setOnAction((ActionEvent event) -> {
    htmlEditor.setHtmlText(htmlEditor.getHtmlText() +
    img);
    });

    • Sorry, the code didn’t look like I expected. So here it is:

      String img =

      btn.setOnAction((ActionEvent event) -> {
      htmlEditor.setHtmlText(htmlEditor.getHtmlText() +
      img);
      });

  2. Thanks, it worked. To set the image source to a file, set the “src” attribute of the image to files uri.
    By calling toURI() on file object. And then call toString() to turn URI object to string. Set this to “src” attribute of img.

Leave a Reply

Your email address will not be published. Required fields are marked *