AbstractElement par = (AbstractElement) getParagraphElement(index); AttributeContext ctx = getAttributeContext();
writeLock();   DefaultDocumentEvent ev = new DefaultDocumentEvent ( offset, length, DocumentEvent.EventType.CHANGE);     Element rootElement = getDefaultRootElement(); int startElement = rootElement.getElementIndex(offset); int endElement = rootElement.getElementIndex(offset + length - 1); if (endElement < startElement) endElement = startElement;  for (int i = startElement; i <= endElement; i++) { Element par = rootElement.getElement(i); MutableAttributeSet a = (MutableAttributeSet) par.getAttributes();  ev.addEdit(new AttributeUndoableEdit(par, attributes, replace));
  public void setParagraphAttributes(int offset, int length,                                     AttributeSet attributes,                                     boolean replace)  {    int index = offset;    while (index < offset + length)      {        AbstractElement par = (AbstractElement) getParagraphElement(index);        AttributeContext ctx = getAttributeContext();        if (replace)          par.removeAttributes(par);        par.addAttributes(attributes);        index = par.getElementCount();      }  }