Display html document with JEditorPane in Java
Description
The following code shows how to display html document with JEditorPane.
Example
// w w w. j av a 2 s . c o m
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 Main {
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);
}
}
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »