日期:2014-05-17  浏览次数:20637 次

JEditorPane 显示网页 解析html代码

方法一
这是比较基本的方法

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(); 
                  } 
?