int index = offset; while (index < offset + length)
try
  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();      }  }