JavaFX – spell check text in textarea

How do I spell check the text entered by users in textarea?

Can this JavaFX component be implemented?

Can I use the standard spell checker for Java for JavaFX?

Solution

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 wrong style in the style sheet

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

Note that you need jdk8 to use codearea

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>