Fill JEditorPane with document - Java Swing

Java examples for Swing:JEditorPane

Introduction

In the following code, the JEditorPane uses an EditorKit depending on the content type.

import java.io.IOException;

import javax.swing.JEditorPane;

public class Main {

  public static void main(String[] args) {
    try {
      JEditorPane editorPane = new JEditorPane("https://www.java2s.com");

      // Handle an HTML Page
      editorPane.setPage("https://www.java2s.com");

      // Handle an RTF file.
      editorPane.setPage("file:///C:/test.rtf");

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Related Tutorials