EditorEx () { EditorEx e = super.createEditor(); e.getCaretModel().moveToOffset(Math.max(0, Math.min(e.getDocument().getTextLength(), unescaped.second))); e.setHorizontalScrollbarVisible(true); e.getDocument().addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent event) { if (manuallyResized.isNull()) { popupRef.get().pack(true, true); } } }); return e; }