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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With