void (int dotIdx) { Runnable selectRunnable = () -> { Editor editor = myNewNameField.getEditor(); if (editor != null) { editor.getSelectionModel().setSelection(0, dotIdx); editor.getCaretModel().moveToOffset(dotIdx); } else { myNewNameField.selectAll(); } }; //noinspection SSBasedInspection SwingUtilities.invokeLater(selectRunnable); }