Highlighting Strings in JavaFX TextArea
The JavaFX TextArea control (as of 2.0.2) does not support rich text editing where text styles (fonts, etc) are mixed.
You can highlight contiguous strings of characters in the TextArea by manipulating the TextArea's selectRange, as in the following example:
public class TextHighlight extends Application {
public static void main(String[] args) { Application.launch(args); }
@Override public void start(Stage stage) {
final TextArea text = new TextArea("Here is some textz to highlight");
text.setStyle("-fx-highlight-fill: lightgray; -fx-highlight-text-fill: firebrick; -fx-font-size: 20px;");
text.setEditable(false);
text.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent t) { t.consume(); }
});
stage.setScene(new Scene(text));
stage.show();
Platform.runLater(new Runnable() {
@Override public void run() { text.selectRange(13, 18); }
});
}
}
You could use the above code as a basis to switch the TextArea to read-only mode while spell checking is happening. Implement prompting to find and fix each word in turn until the spell check is complete. Perform the prompting in a separate dialog or panel. The Jazzy demo seems to work this way http://jazzy.sourceforge.net/demo.html, so it should be fairly easy to convert its Swing UI to JavaFX.
Alternately, you could use a JavaFX WebView control to wrap any of the many javascript/html based spell checkers (e.g. http://www.javascriptspellcheck.com/) using a technique similar to what is demonstrated here: http://jewelsea.wordpress.com/2011/12/11/codemirror-based-code-editor-for-javafx/.
RichTextFX allows you to add style to text ranges.