rootElement.replace(i1, i2 - i1 + 1, added);
((BranchElement) rootElement).replace(i1, i2 - i1 + 1, added);
  protected void removeUpdate(DefaultDocumentEvent event)  {    super.removeUpdate(event);    // added and removed are Element arrays used to add an ElementEdit    // to the DocumentEvent if there were entire lines added or removed    // from the Document    Element[] added = new Element[1];    Element[] removed;    int p0 = event.getOffset();    // check if we must collapse some elements    int i1 = rootElement.getElementIndex(p0);    int i2 = rootElement.getElementIndex(p0 + event.getLength());    if (i1 != i2)      {        // If there were lines removed then we have to add an ElementEdit        // to the DocumentEvent so we set it up now by filling the Element        // arrays "removed" and "added" appropriately        removed = new Element [i2 - i1 + 1];        for (int i = i1; i <= i2; i++)          removed[i-i1] = rootElement.getElement(i);                int start = rootElement.getElement(i1).getStartOffset();        int end = rootElement.getElement(i2).getEndOffset();                added[0] = createLeafElement(rootElement,                                          SimpleAttributeSet.EMPTY,                                          start, end);        // Now create and add the ElementEdit        ElementEdit e = new ElementEdit(rootElement, i1, removed, added);        event.addEdit(e);        // collapse elements if the removal spans more than 1 line        rootElement.replace(i1, i2 - i1 + 1, added);      }    }