【问题标题】:Spell check text in TextAreaTextArea 中的拼写检查文本
【发布时间】:2014-01-02 08:59:31
【问题描述】:

如何检查用户输入到 TextArea 的文本?

这个 JavaFX 组件可以实现吗?

我可以为 JavaFX 使用来自 Java 的标准拼写检查器吗?

【问题讨论】:

标签: javafx javafx-2 javafx-8


【解决方案1】:

您可以使用CodeArea 突出显示错误。

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.
}

另外,在你的样式表中设置错误样式

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

请注意,您需要 JDK8 才能使用 CodeArea。

【讨论】:

    猜你喜欢
    • 2022-01-02
    • 2010-12-28
    • 1970-01-01
    • 2016-03-14
    • 2011-07-02
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多