0
我想刪除JTextPane中的第一行並設置setContentType(「text/html」);能夠在JTextPane中使用html標籤。如何刪除JTextPane中的第一行並設置setContentType(「text/html」)
當我使用此代碼
的setContentType( 「text/html的」);
try {
Element root = getDocument().getDefaultRootElement();
Element firstLine = root.getElement(0);
getDocument().remove(firstLine.getStartOffset(), firstLine.getEndOffset());
}
catch (Exception e) {e.toString();}
我得到一個異常
javax.swing.text.BadLocationException: Invalid remove
如果我評論的setContentType( 「text/html的」);我可以從JTextPane中刪除第一行。