void (@NotNull FocusableContext context, @NotNull Runnable task) { boolean hadFocus = context.isFocusedInWindow(); // if (hadFocus) KeyboardFocusManager.getCurrentKeyboardFocusManager().clearFocusOwner(); task.run(); if (hadFocus) context.requestFocusInWindow(); }