int caretPos = textComponent.getCaretPosition(); if (caretPos >= ev.getOffset()) textComponent.setCaretPosition(caretPos + ev.getLength());
    public void insertUpdate(DocumentEvent ev)    {      Dimension size = textComponent.getSize();      rootView.insertUpdate(ev, new Rectangle(0, 0, size.width, size.height),                            BasicTextUI.this);    }