5

How I can spell check text typed from the user into TextArea?

Is this possible with this JavaFX component?

Can I use standard spellchecker from Java for JavaFX?

Amit Verma
  • 39,545
  • 18
  • 87
  • 107
Peter Penzov
  • 2,352
  • 100
  • 358
  • 675
  • possible duplicate of [Highlighting Strings in JavaFX TextArea](http://stackoverflow.com/questions/9128535/highlighting-strings-in-javafx-textarea) – jewelsea Dec 14 '13 at 19:03
  • Does this answer your question? [JavaFX Spell checker using RichTextFX how to create right click suggestions](https://stackoverflow.com/questions/72204764/javafx-spell-checker-using-richtextfx-how-to-create-right-click-suggestions) – trilogy May 18 '22 at 16:21

1 Answers1

3

You can use CodeArea to highlight the errors.

CodeArea codeArea = new CodeArea();
codeArea.textProperty().addListener((observable, oldText, newText) -> {
    List<IndexRange> errors = spellCheck(newText);
    for(IndexRange error: errors) {
        codeArea.setStyleClass(error.getStart(), error.getEnd(), "spell-error");
    }
});

List<IndexRange> spellCheck(String text) {
    // Implement your spell-checking here.
}

In addition, set the error style in your stylesheet

.spell-error {
    -fx-effect: dropshadow(gaussian, red, 2, 0, 0, 0);
}

Note that you need JDK8 to use CodeArea.

Tomas Mikula
  • 6,457
  • 23
  • 38