code: private void insertImage() {
          String initialDir = System.getProperty("user.dir");
          FileChooser fileChooser = new FileChooser();
          fileChooser.setTitle("Insert image");
          fileChooser.setInitialDirectory(new File(initialDir));
          File selectedFile = fileChooser.showOpenDialog(mainStage);
          if (selectedFile != null) {
              String imagePath = selectedFile.getAbsolutePath();
              imagePath = imagePath.replace('\\',  '/');
              ReadOnlyStyledDocument<ParStyle, Either<String, LinkedImage>, TextStyle> ros =
                      ReadOnlyStyledDocument.fromSegment(Either.right(new RealLinkedImage(imagePath)),
                                                         ParStyle.EMPTY, TextStyle.EMPTY, area.getSegOps());
              area.replaceSelection(ros);
          }
      }
docs: Action listener which inserts a new image at the current caret position.