TextMate (VSCode) syntax highlighting for JavaFX.
This project is powered by tm4java and offers TextMate syntax highlighting
for TextFlow, RichTextArea and CodeArea.
Note that JavaFX RichTextArea is in the incubator, so it requires an early access (EA) build, and the API may be subject to changes.
Maven:
<dependency>
<groupId>io.github.mkpaz</groupId>
<artifactId>tm4javafx</artifactId>
<version>0.1.0</version>
</dependency>Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation 'io.github.mkpaz:tm4javafx:0.1.0'
}var styleProvider = new StyleProvider();
styleProvider.setGrammar(IGrammarSource.fromFile(
Resources.getFile("/tm4javafx/demo/grammars/java.tmLanguage.json")
));
styleProvider.setTheme(IThemeSource.fromFile(
Resources.getFile("/tm4javafx/demo/themes/one-dark-pro.json")
));
final String sampleText = """
public static void main(String[] args) {
System.out.println("Hello World!");
}
""";
var richTextArea = new RichTextArea();
richTextArea.setPrefHeight(200);
var richTextAreaModel = new RichTextAreaModel();
richTextAreaModel.setRichTextArea(richTextArea);
richTextAreaModel.setStyleProvider(styleProvider);
richTextAreaModel.setText(sampleText);
var scene = new Scene(richTextArea, 800, 600);
stage.setScene(scene);
stage.setOnShown(_ -> {
StyleHelper.applyThemeSettings(richTextArea, styleProvider.getThemeSettings());
});
stage.show();You can find the full version of this in UsageExample.java.
To run the demo (shown in the screenshot) and play with grammars/themes, use:
mvn install
cd demo
JAVA_HOME=/path/to/jdk/24 mvn javafx:run