Loading HTML Documents as a StyledDocument into a JEditorPane : JEditorPane « Swing « Java Tutorial






The JEditorPane class provides the ability to display and edit multiple-attributed text.

import java.awt.BorderLayout;
import java.io.FileReader;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;

public class LoadingHTMLDocuments {
  public static void main(String args[])throws Exception {
    JFrame frame = new JFrame("Tab Attributes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKit(new HTMLEditorKit());
    
    String filename = "yourFile.htm";
    
    FileReader reader = new FileReader(filename);
    editorPane.read(reader, filename);

    JScrollPane scrollPane = new JScrollPane(editorPane);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}








14.35.JEditorPane
14.35.1.Loading HTML Documents as a StyledDocument into a JEditorPane
14.35.2.Loading Web Page To JEditorPaneLoading Web Page To JEditorPane
14.35.3.Using Actions with Text Components: JEditorPane
14.35.4.Show html
14.35.5.Change mouse cursor during mouse-over action on hyperlinks
14.35.6.JEditorPane Look and Feel
14.35.7.How to change mouse cursor during mouse-over action on hyperlinks