在JTextPane中追加Html内容
import java.io.IOException;
import javax.swing.JTextPane;
import BadLocationException;
import Document;
import html.HTMLDocument;
/**
*
* @author Administrator
*/
public class MyTextPane extends JTextPane{
/
** Creates a new instance of JTextPanel_N */
StringBuffer temp=new StringBuffer();
html.HTMLDocument hd;
int tempnum=0;
public MyTextPane() {
super.setContentType("text/html");
super.setEditable(false);
hd=new HTMLDocument();
hd=(HTMLDocument) Document();
}
/***/
html document是什么
public void addText(String str) {
if(tempnum==0) {
try {
hd.DefaultRootElement(),str);
} catch (BadLocationException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
tempnum++;
} else {
try {
System.out.println("Document().getEndPosition().getOffset() is: "+Document().getEndPosition().getOffset());
hd.DefaultRootElement(),str);
super.Document().getLength());
} catch (BadLocationException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
//temp.append(str);
// super.String());
}
}
使⽤时调⽤MyTextPane类的addText("这⾥是追加的html代码")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。