CodeArea codeArea = new CodeArea();
String stylesheet = JavaKeywords.class.getResource("java-keywords.css").toExternalForm();
IntFunction<String> format = (digits -> " %" + digits + "d ");
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea, format, stylesheet));
codeArea.textProperty().addListener((obs, oldText, newText) -> {
codeArea.setStyleSpans(0, computeHighlighting(newText));
});
codeArea.replaceText(0, 0, sampleCode);
Scene scene = new Scene(new StackPane(codeArea), 600, 400);