在TextArea中拼写检查文本 [英] Spell check text in TextArea
本文介绍了在TextArea中拼写检查文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何拼写检查从用户输入的文本到TextArea?
How I can spell check text typed from the user into TextArea?
这个JavaFX组件可以实现吗?
Is this possible with this JavaFX component?
我可以使用Java for JavaFX的标准拼写检查器吗?
Can I use standard spellchecker from Java for JavaFX?
推荐答案
你可以使用 CodeArea 突出显示错误。
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);
}
请注意,您需要JDK8才能使用CodeArea。
Note that you need JDK8 to use CodeArea.
这篇关于在TextArea中拼写检查文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文