Back to LanguageTool Homepage - Privacy - Imprint

JavaFX library that implements LanguageTool like on frontpage?


Hi looking if a library exists that pretty has a control that is a "textarea" that has a built in spell checker like that on front page of languagetool.

I looked into trying to code me own using RichTextFX, as javaFX TextArea does not support multiple styles.

RichTextFx doesn't really have a forum so i thought I bring it up here.

Code so far:

package application;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import org.languagetool.JLanguageTool;
import org.languagetool.language.AmericanEnglish;
import org.languagetool.rules.RuleMatch;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SpellChecking extends Application {

	static List<String> misspells = new ArrayList<>();
	static List<RuleMatch> matches = new ArrayList<>();
    StyleClassedTextArea textArea = new StyleClassedTextArea();
	JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
	String input = "this is a sentence with soeme errors";
	 public void start(Stage primaryStage) throws IOException {
        textArea.insertText(0, input);
        Scene scene = new Scene(new VirtualizedScrollPane<>(textArea), 600, 400);
        primaryStage.setTitle("Spell Checking Demo");;

    private void checkSpelling() throws IOException {
    	  matches = langTool.check(input);
          matches.forEach(match -> {
              int start = match.getFromPos();
              int end = match.getToPos();
              misspells.add(input.substring(start, end)); 
          textArea.setStyleSpans(0, computeHighlighting(textArea.getText()));

    private static StyleSpans<Collection<String>> computeHighlighting(String text) {
        StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
        BreakIterator wb = BreakIterator.getWordInstance();

        int lastIndex = wb.first();
        int lastKwEnd = 0;
        while(lastIndex != BreakIterator.DONE) {
            int firstIndex = lastIndex;
            lastIndex =;

            if (lastIndex != BreakIterator.DONE && Character.isLetterOrDigit(text.charAt(firstIndex))) {
                String word = text.substring(firstIndex, lastIndex).toLowerCase();
                if (misspells.contains(word)) {
                    spansBuilder.add(Collections.emptyList(), firstIndex - lastKwEnd);
                    spansBuilder.add(Collections.singleton("underlined"), lastIndex - firstIndex);
                    lastKwEnd = lastIndex;
        spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);

        return spansBuilder.create();
    public static void main(String[] args) {


.underlined {
    -rtfx-background-color: #f0f0f0;
    -rtfx-underline-color: red;
    -rtfx-underline-dash-array: 2 2;
    -rtfx-underline-width: 1;
    -rtfx-underline-cap: butt;