Skip to content

raghul-tech/Swing-Markdown-Preview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿ“ Swing Markdown Preview

Render beautiful GitHub-style Markdown in your Java Swing apps.

โšก Lightweight. ๐Ÿ’ผ Production Ready. ๐Ÿงฉ Fully Customizable.

Maven Central Build Status CodeQL Security Javadoc Latest Release Buy Me A Coffee


โœจ What is Swing Markdown Preview?

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.


๐ŸŽฏ Who Is It For?

  • ๐Ÿงฑ 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


โš–๏ธ Minimal vs All-In-One JAR

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

๐Ÿš€ Installation

โœจ All-In-One (Recommended for most users)

Maven

<dependency>
  <groupId>io.github.raghul-tech</groupId>
  <artifactId>swing-markdown-preview-all</artifactId>
  <version>1.0.0</version>
</dependency>

๐Ÿชถ Minimal (No Flexmark bundled)

Maven

<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>

๐Ÿ’ก Features

โœ… GitHub-style Markdown rendering โœ… Live updates โœ… Theme switching โœ… Optional Flexmark bundling โœ… Fat jar available โœ… Java 8+ compatible


๐Ÿงฉ Usage Examples by Class

  • Below are examples of how to use each main class:

๐ŸŽฏ 1. SwingMarkdownTabbedPreview

  • Use this when you want to add a Markdown preview tab to your own JTabbedPane.

  • โœ… Perfect for apps with multiple tabs (like editors).

โœจ Example:

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);
    }
}

๐ŸŽฏ 2. SwingMarkdownScrollPanePreview

  • Use this when you want a JScrollPane with preview content you can embed in any layout.

  • โœ… Great if you want scrolling built in.

โœจ Example:

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);
    }
}

๐ŸŽฏ 3. SwingMarkdownPanelPreview

  • Use this if you need a JPanel you can put anywhere.

  • โœ… Ideal for embedding in custom UIs.

โœจ Example:

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);
    }
}

๐ŸŽฏ 4. SwingMarkdownWindowPreview

  • Use this when you want a standalone window that displays your Markdown.

  • โœ… Great for โ€œPreviewโ€ buttons.

โœจ Example:

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();
    }
}

๐Ÿ—๏ธ Example Projects

โœ… To run an example:

  1. Download or clone this repository.

  2. Navigate to examples/.

  3. Compile and run the desired file.


๐ŸŽจ MarkdownTheme

  • Simple enum to toggle light or dark theme.

โœ… Available values:

  • ๐Ÿ”น Example:
preview.isDarkMode(true);

You can call isDarkMode() any timeโ€”your preview updates immediately.


๐Ÿ“‚ How to Use the JAR

Compile:

javac -cp swing-markdown-preview-all-1.0.0.jar MyPreviewApp.java

Run:

Windows:

java -cp .;swing-markdown-preview-all-1.0.0.jar MyPreviewApp

macOS/Linux:

java -cp .:swing-markdown-preview-all-1.0.0.jar MyPreviewApp

๐Ÿ” Documentation


๐Ÿ†• Changelog


๐Ÿค Contributing

  • We welcome all contributions!

    • ๐Ÿ› Bug fixes

    • โœจ Features

    • ๐Ÿ“ Documentation improvements

    • ๐Ÿงช Example enhancements

๐Ÿ‘‰ Contributing Guide


๐Ÿž Report a Bug


๐Ÿ“„ License


โ˜• Support

About

๐Ÿ“Swing Markdown Preview is a Java library to render GitHub-flavored Markdown in Swing apps. Supports live preview, themes, emoji, tables, and Flexmark integration out of the box.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages