Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;
import java.io.StringReader;

import javax.swing.JEditorPane;

import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;

public class Main {
    public static void setPaneHtmlText(String htmlText, JEditorPane pane) {
        if (htmlText == null) {
            pane.setText("");
            return;
        } else if (htmlText.length() == 0) {
            pane.setText("");
            return;
        }

        StringReader htmReader = new StringReader(htmlText);
        HTMLEditorKit kit = (HTMLEditorKit) pane.getEditorKitForContentType("text/html");
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();

        ParserDelegator parser = new ParserDelegator();
        try {
            parser.parse(htmReader, doc.getReader(0), true);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        pane.setDocument(doc);
    }
}