[ Back | Previous | Next ]

How to append text into JEditorPane with insertString and AttributeSet?

Package:
javax.swing.text.*
Product:
Swing
Release:
1.1.x
Related Links:
General
JEditorPane
PlainDocument
Comment:
		Document doc = (Document) editorPane.getDocument();
		Element e = doc.getDefaultRootElement();
		// Copy attribute Set
		AttributeSet attr = e.getAttributes().copyAttributes();
		dbg("-- attr = " + attr );
		dbg("-- length = " + doc.getLength() );
		doc.insertString(doc.getLength(), "Naam", attr);

For exampe:

public void setErrorURL(String newValue, Exception e) { this.errorURL = newValue; try { getEditorPane().setPage(getErrorPath() + newValue); try { Document doc = (Document) getEditorPane().getDocument(); // Copy attribute Set AttributeSet attr = ((HTMLEditorKit) getEditorPane().getEditorKit()).getInputAttributes(); dbg("-- attr = " + attr); dbg("-- length = " + doc.getLength()); doc.insertString(doc.getLength(), "Exception", null); } catch (Throwable bl) { dbg("-- " + bl.getMessage()); } } catch (java.io.IOException ioe) { handleException(ioe); } }