Render beautiful GitHub-style Markdown in your Java Swing apps.
โก Lightweight. ๐ผ Production Ready. ๐งฉ Fully Customizable.
Swing Markdown Preview is a modern Java library to display Markdown content in Swing applications.
With GitHub-like styling, theme switching, and live updating, you can turn your text into beautifully rendered HTML without complex setup.
-
๐งฑ Java Swing Developers needing Markdown rendering
-
๐ Note-taking or documentation tool makers
-
๐งโ๐ซ Students or teachers building markdown-based learning tools
-
โ๏ธ IDE or editor plugin developers needing a quick Markdown viewer
| Variant | Includes Flexmark? | Use Case |
|---|---|---|
| swing-markdown-preview | โ No | Maven users managing dependencies manually |
| swing-markdown-preview-all | โ Yes (flexmark-all) | Anyone who wants it to "just work" out of the box |
<dependency>
<groupId>io.github.raghul-tech</groupId>
<artifactId>swing-markdown-preview-all</artifactId>
<version>1.0.0</version>
</dependency><dependency>
<groupId>io.github.raghul-tech</groupId>
<artifactId>swing-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>โ GitHub-style Markdown rendering โ Live updates โ Theme switching โ Optional Flexmark bundling โ Fat jar available โ Java 8+ compatible
- Below are examples of how to use each main class:
-
Use this when you want to add a Markdown preview tab to your own JTabbedPane.
-
โ Perfect for apps with multiple tabs (like editors).
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.*;
import io.github.raghultech.markdown.swing.preview.SwingMarkdownTabbedPreview;
public class ExampleSwingTab {
public static void main(String[] args) {
JFrame frame = new JFrame("Markdown Preview Tabs");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 900);
frame.setLocationRelativeTo(null);
frame.setLayout(new BorderLayout());
// Create your tabbed pane
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Editor 1", new JScrollPane(new JTextArea()));
tabbedPane.addTab("Editor 2", new JScrollPane(new JTextArea()));
frame.add(tabbedPane, BorderLayout.CENTER);
// Create preview and attach it
File markdownFile = new File("README.md");
SwingMarkdownTabbedPreview preview = new SwingMarkdownTabbedPreview(tabbedPane, markdownFile);
preview.launchPreviewTab();
frame.setVisible(true);
}
}-
Use this when you want a JScrollPane with preview content you can embed in any layout.
-
โ Great if you want scrolling built in.
import java.awt.Desktop;
import java.io.File;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import io.github.raghultech.markdown.swing.preview.SwingMarkdownScrollPanePreview;
public class ExampleSwingScrollPane {
public static void main(String[] args) {
File markdownFile = new File("README.md");
// Optionally use your own JEditorPane for custom behavior
/*
* if u want u can add a JEditorPane or leave it will take care
*/
JEditorPane myPane = new JEditorPane();
myPane.setContentType("text/html");
myPane.setEditable(false);
myPane.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
SwingMarkdownScrollPanePreview preview = new SwingMarkdownScrollPanePreview(markdownFile);
preview.setEditorPane(myPane);
JScrollPane previewPane = preview.createPreview();
JFrame frame = new JFrame("Markdown ScrollPane Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.add(previewPane);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}-
Use this if you need a JPanel you can put anywhere.
-
โ Ideal for embedding in custom UIs.
import java.io.File;
import javax.swing.*;
import io.github.raghultech.markdown.swing.preview.SwingMarkdownPanelPreview;
public class ExampleSwingPanel {
public static void main(String[] args) {
JFrame frame = new JFrame("Markdown Panel Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
File file = new File("README.md");
SwingMarkdownPanelPreview previewPanel = new SwingMarkdownPanelPreview(file);
frame.getContentPane().add(previewPanel);
frame.setVisible(true);
}
}-
Use this when you want a standalone window that displays your Markdown.
-
โ Great for โPreviewโ buttons.
import java.io.File;
import javax.swing.JFrame;
import io.github.raghultech.markdown.swing.preview.SwingMarkdownWindowPreview;
public class ExampleSwingWindow {
public static void main(String[] args) {
File file = new File("README.md");
SwingMarkdownWindowPreview preview = new SwingMarkdownWindowPreview(file);
preview.setWindowTitle("My Markdown Viewer");
preview.setWindowSize(900, 700);
preview.launchPreview();
}
}-
Youโll find ready-to-run examples in the examples/ directory:
-
ExampleSwingPanel.javaโ Embed preview as a JPanel -
ExampleSwingScrollPane.javaโ Use preview inside a JScrollPane -
ExampleSwingTab.javaโ Add preview as a new tab in JTabbedPane -
ExampleSwingWindow.javaโ Show preview in a standalone window
-
โ To run an example:
-
Download or clone this repository.
-
Navigate to examples/.
-
Compile and run the desired file.
- Simple enum to toggle light or dark theme.
- ๐น Example:
preview.isDarkMode(true);You can call isDarkMode() any timeโyour preview updates immediately.
javac -cp swing-markdown-preview-all-1.0.0.jar MyPreviewApp.javaWindows:
java -cp .;swing-markdown-preview-all-1.0.0.jar MyPreviewAppmacOS/Linux:
java -cp .:swing-markdown-preview-all-1.0.0.jar MyPreviewApp-
๐ 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 โค๏ธ