Text spell checker in TextArea

How can I check the validation text entered by the user in TextArea?

Is this possible with this JavaFX component?

Can I use the standard Java spell checker for JavaFX?

+4
source share
1 answer

You can use CodeArea to highlight 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.
}

Also, set the error style in the stylesheet.

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

Please note that you need JDK8 to use CodeArea.

+2
source

All Articles