JEditorPane pane = new JEditorPane() {
private static final long serialVersionUID = 1L;
@Override
protected EditorKit createDefaultEditorKit() {
return new StyledEditorKit();
}
};
pane.setEditorKit(new StyledEditorKit());
StyledDocument doc = (StyledDocument) pane.getDocument();
StyledEditorKit kit = (StyledEditorKit) pane.getEditorKit();
try {
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setUnderline(attrs, true);
doc.insertString(0, "Hello word!", attrs);
pane.setCaretPosition(4);
attrs = new SimpleAttributeSet();
StyleConstants.setIcon(attrs, MetalIconFactory.getTreeFolderIcon());
doc.insertString(4, " ", attrs);
pane.setCaretPosition(4);
doc.insertString(4, "\n", kit.getInputAttributes());
assertFalse(StyleConstants.isUnderline(kit.getInputAttributes()));
pane.setCaretPosition(5);
assertFalse(StyleConstants.isUnderline(kit.getInputAttributes()));
} catch (BadLocationException e) {
}
}