Render rich, real-time Markdown previews inside Java Swing apps using JavaFX WebView.
โก Fast. ๐ผ๏ธ Beautiful. ๐ฏ Real-Time. ๐ Theme-Aware.
SwingFX-Markdown-Preview is a modern library for rendering live, GitHub-style Markdown previews inside Java Swing applications.
It uses JavaFX WebView embedded inside Swing via JFXPanel
to deliver smoother, more advanced rendering than traditional JEditorPane
or HTMLEditorKit
.
- ๐ฆ Works inside any Swing app
- ๐ Uses JavaFX WebView via
JFXPanel
(not JavaFX stage) - ๐ง Real-time preview updates as the file changes
- ๐จ Theme support (light/dark toggle)
- ๐งฉ Modular architecture (choose minimal or fat jar)
- ๐งฐ Includes Flexmark (optionally) for Markdown parsing
- โ Compatible with JavaFX 11+ and Java 8+
Artifact Name | Includes Flexmark | Includes JavaFX | Use Case |
---|---|---|---|
swingfx-markdown-preview |
โ No | โ No | For Maven users with own setup |
swingfx-markdown-preview-flexmark |
โ Yes | โ No | Add your own JavaFX separately |
swingfx-markdown-preview-all |
โ Yes | โ Yes | Just works, no manual setup |
<dependency>
<groupId>io.github.raghul-tech</groupId>
<artifactId>swingfx-markdown-preview-all</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.github.raghul-tech</groupId>
<artifactId>swingfx-markdown-preview-flexmark</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21.0.1</version>
</dependency>
<!-- Also include: javafx-web, javafx-swing, javafx-fxml, javafx-graphics, javafx-base -->
<dependency>
<groupId>io.github.raghul-tech</groupId>
<artifactId>swingfx-markdown-preview</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.64.8</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21.0.1</version>
</dependency>
<!-- Also include: javafx-web, javafx-swing, javafx-fxml, javafx-graphics, javafx-base -->
-
โ Live File Monitoring: auto-refreshes when Markdown file changes
-
โ GitHub-Flavored Markdown (matches the style of GitHub's Markdown)
-
โ Theme Toggle: light or dark mode with
.setDarkMode(true)
-
โ HTML Export: easily convert Markdown to clean, styled HTML strings
-
โ Emoji Support
-
โ Component Types:
- MarkdownPanel
- MarkdownTabbedview
- MarkdownWindow
- MarkdownRenderer (no GUI)
-
โ HTML export and emoji support
-
โ No JavaFX Stage needed
import io.github.raghultech.markdown.swingfx.preview.MarkdownWindow;
import java.io.File;
public class PreviewDemo {
public static void main(String[] args) {
File file = new File("README.md");
MarkdownWindow preview = new MarkdownWindow(file);
preview.setWindowTitle("Markdown Live Preview");
preview.setWindowSize(700, 700);
// preview.isDarkMode(true);
preview.launchPreview();
}
}
- Toggle dark mode anytime:
preview.setDarkMode(true); // dark mode ON
preview.setDarkMode(false); // light mode
- Live updates automatically.
javac -cp swingfx-markdown-preview-all-1.0.0.jar MyPreviewApp.java
Windows:
java -cp .;swingfx-markdown-preview-all-1.0.0.jar MyPreviewApp
macOS/Linux:
java -cp .:swingfx-markdown-preview-all-1.0.0.jar MyPreviewApp
-
Youโll find ready-to-run examples in the examples/ directory:
-
ExamplePanel.java
โ Embed preview as a JPanel -
ExampleTabbedPane.java
โ Add preview as a new tab in JTabbedPane -
ExampleWindow.java
โ Show preview in a standalone window -
ExampleRenderer.java
โ convert a Markdown file to styled HTML
-
โ To run an example:
-
Download or clone this repository.
-
Navigate to examples/.
-
Compile and run the desired file.
-
๐ Javadoc
-
๐ Changelog
-
โ Issue Tracker
- see CHANGELOG.md for release history.
-
We welcome all contributions!
-
๐ Bug fixes
-
โจ Features
-
๐ Documentation improvements
-
๐งช Example enhancements
-
๐ Contributing Guide
- Found an issue? Open an Issue with clear details.
- This project is licensed under the MIT License.
- If you love this project, you can Buy Me a Coffee โค