start, end - len); rootElement.replace(i1, i2 - i1, new Element[]{ newEl });
start, end); rootElement.replace(i1, i2 - i1 + 1, new Element[]{ newEl });
  protected void removeUpdate(DefaultDocumentEvent event)  {    super.removeUpdate(event);    int p0 = event.getOffset();    int len = event.getLength();    int p1 = len + p0;    // check if we must collapse some elements    int i1 = rootElement.getElementIndex(p0);    int i2 = rootElement.getElementIndex(p1);    if (i1 != i2)      {        Element el1 = rootElement.getElement(i1);        Element el2 = rootElement.getElement(i2);        int start = el1.getStartOffset();        int end = el2.getEndOffset();        // collapse elements if the removal spans more than 1 line        Element newEl = createLeafElement(rootElement,                                          SimpleAttributeSet.EMPTY,                                          start, end - len);        rootElement.replace(i1, i2 - i1, new Element[]{ newEl });      }    }