方法一
这是比较基本的方法
JEditPane XD = new JEditPane();
XD.setEditorKit(new HTMLEditorKit());
XD.setText( " <h1> zz </h1> ");
[编辑 ] 方法二
方法一最大的缺点在于说 , 如果你有一狗票的内容 HTML, 要这么傻傻地用 的setText () 的方式去输入吗 ? 当然有别的方法 , 首先我们另外写一个 HTML 档 , 暂且称之为 “ sample.html ” 接着用 InputStreamer 去读取它 。
JEditPane XD = new JEditPane();
XD.setContentType( "text/html ");
HTMLEditorKit kit = new HTMLEditorKit();
XD.setEditorKit(kit);
HTMLDocument doc = (HTMLDocument)XD.getDocument();
File f = new File( "sample.html ");
try {
FileInputStream reader = new FileInputStream(f);
kit.read(reader,doc,0);
}catch(Exception e) {
e.printStackTrace();
}