void (Object anObject) { if (anObject == null) anObject = ""; if (anObject.equals(getItem())) return; final String s = (String)anObject; WriteCommandAction.writeCommandAction(myProject).run(() -> getDocument().setText(s)); final Editor editor = getEditor(); if (editor != null) editor.getCaretModel().moveToOffset(s.length()); }