Example usage for javax.swing JEditorPane getEditorKitForContentType

List of usage examples for javax.swing JEditorPane getEditorKitForContentType

Introduction

In this page you can find the example usage for javax.swing JEditorPane getEditorKitForContentType.

Prototype

public EditorKit getEditorKitForContentType(String type) 

Source Link

Document

Fetches the editor kit to use for the given type of content.

Usage

From source file:Main.java

public static void setPaneHtmlText(String htmlText, JEditorPane pane) {
    if (htmlText == null) {
        pane.setText("");
        return;/*from  w  w  w.j  av  a 2s .  c o  m*/
    } 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);
}