Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spell check text in TextArea

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?

like image 224
Peter Penzov Avatar asked Oct 03 '22 04:10

Peter Penzov


1 Answers

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.

like image 154
Tomas Mikula Avatar answered Oct 13 '22 10:10

Tomas Mikula