private static void focusAndRun(@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();
          }
        });
      }
    }
private static void focusAndRun(@NotNull Component component, @NotNull Runnable runnable)