Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.minus199:RichTextFX:0.7-M2'
}
dependencies {
implementation("com.github.minus199:RichTextFX:0.7-M2")
}
<dependency>
<groupId>com.github.minus199</groupId>
<artifactId>RichTextFX</artifactId>
<version>0.7-M2</version>
</dependency>
libraryDependencies += "com.github.minus199" % "RichTextFX" % "0.7-M2"
:dependencies [[com.github.minus199/RichTextFX "0.7-M2"]]
RichTextFX provides a text area for JavaFX with API to style ranges of text. It is intended as a base for rich-text editors and code editors with syntax highlighting.
Kappa IDE
Squirrel SQL client (its JavaFX version)
mqtt-spy
Alt.Text
Xanthic
Arduino Harp
Markdown Writer FX
OmniEditor, which is then used by Chronos IDE
If you use RichTextFX in an interesting project, I would like to know!
StyleClassedTextArea
lets you assign style classes to ranges of text. You can define the style classes in your stylesheet.
Example.java:
area.setStyleClass(from, to, "red");
example.css:
.red { -fx-fill: red; }
This renders the text in the range [from, to)
in red.
Note that the style classes are assigned to instances of Text, so you can specify any CSS properties applicable to a Text node.
CodeArea
is a variant of StyleClassedTextArea
that uses a fixed width font by default, making it a convenient base for source code editors. CodeArea
is used in the Java Keywords demo below.
InlineCssTextArea
lets you specify inline CSS for a range of text.
area.setStyle(from, to, "-fx-font-weight: bold;");
Again, you can use any CSS properties applicable to a Text
node.
InlineStyleTextArea<S>
is a more general version of InlineCssTextArea
. In the end, there is still inline CSS assigned to Text
nodes, but instead of using the CSS string directly, you use an instance of your custom style representation S
and provide a way (function) to convert S
to CSS string in InlineStyleTextArea
constructor.
class MyStyleInfo {
boolean bold;
boolean italic;
String toCss() {
return "-fx-font-weight: " + (bold ? "bold" : "normal") + ";"
+ "-fx-font-style: " + (italic ? "italic" : "normal") + ";";
}
}
InlineStyleTextArea<MyStyleInfo> area =
new InlineStyleTextArea<>(new MyStyleInfo(), styleInfo -> styleInfo.toCss());
The first constructor argument is the default style to use for ranges of text where you don't set the style explicitly. The second constructor argument is the function to convert the custom style representation to CSS.
You then assign an instance of your custom style representation to a range of text.
MyStyleInfo styleInfo = ...;
area.setStyle(from, to, styleInfo);
You appreciate the benefits of this approach over InlineCssTextArea
when you need to query the style used at a given position in text - you get back an instance of your style representation instead of a CSS string.
MyStyleInfo styleInfo = area.getStyleAt(charIndex);
InlineStyleTextArea
is used in the Rich-text demo below.
JDK8 is required, because TextFlow, introduced in JavaFX 8.0, is used to render each line. Also, there's a heavy use of lambdas, defender methods and the stream API in the code base.
JDK 8u40 is recommended, because it fixes some text rendering bugs.
Download the pre-built "fat" JAR file and run
java -cp richtextfx-demos-fat-0.6.10.jar org.fxmisc.richtext.demo.JavaKeywords
or
java -cp richtextfx-demos-fat-0.6.10.jar org.fxmisc.richtext.demo.JavaKeywordsAsync
gradle JavaKeywords
or
gradle JavaKeywordsAsync
The former computes highlighting on the JavaFX application thread, while the latter computes highlighting on a background thread.
Similar to the Java Keywords demo above, this demo highlights XML syntax. Courtesy of @cemartins.
Download the pre-built "fat" JAR file and run
java -cp richtextfx-demos-fat-0.6.10.jar org.fxmisc.richtext.demo.XMLEditor
gradle XMLEditor
Download the pre-built "fat" JAR file and run
java -cp richtextfx-demos-fat-0.6.10.jar org.fxmisc.richtext.demo.richtext.RichText
gradle RichText
When the mouse pauses over the text area, you can get index of the character under the mouse. This allows you to implement, for example, custom tooltips whose content depends on the text under the mouse.
Download the pre-built "fat" JAR file and run
java -cp richtextfx-demos-fat-0.6.10.jar org.fxmisc.richtext.demo.TooltipDemo
gradle TooltipDemo
Current stable release is 0.6.10.
| Group ID | Artifact ID | Version | | :-----------------: | :---------: | :-----: | | org.fxmisc.richtext | richtextfx | 0.6.10 |
dependencies {
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.6.10'
}
libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "0.6.10"
Download the JAR file or the fat JAR file (including dependencies) and place it on your classpath.
Milestone version of the upcoming release is 0.7-M2.
| Group ID | Artifact ID | Version | | :-----------------: | :---------: | :-----: | | org.fxmisc.richtext | richtextfx | 0.7-M2 |
dependencies {
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.7-M2'
}
libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "0.7-M2"
Download the JAR file or the fat JAR file (including dependencies) and place it on your classpath.
Snapshot releases are deployed to Sonatype snapshot repository.
| Group ID | Artifact ID | Version | | :-----------------: | :---------: | :------------: | | org.fxmisc.richtext | richtextfx | 1.0.0-SNAPSHOT |
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT'
}
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "1.0.0-SNAPSHOT"
Dual-licensed under BSD 2-Clause License and GPLv2 with the Classpath Exception.
There are many ways how you can contribute: