Spell check text in TextArea

若如初见. 提交于 2019-12-01 17:31:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20586032/spell-check-text-in-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!