void (@NotNull Component component, @NotNull Runnable runnable) { component.requestFocus(); if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == component) { runnable.run(); } else { component.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { component.removeFocusListener(this); runnable.run(); } }); } }