public static @Nullable Component getMostRecentComponent(Component component, Window ancestor) {
    if (ancestor == null) {
      return null;
    }

    try {
      MethodHandles.Lookup lookup = MethodHandles.lookup();
      MethodHandle owner =
        lookup.findStatic(KeyboardFocusManager.class, "getMostRecentFocusOwner", MethodType.methodType(Component.class, Window.class));
      Component mostRecentFocusOwner = (Component)owner.invokeExact(ancestor);
      if (mostRecentFocusOwner != null &&
          SwingUtilities.isDescendingFrom(mostRecentFocusOwner, component) &&
          mostRecentFocusOwner.isShowing()) {
        return mostRecentFocusOwner;
      }
    }
    catch (Throwable e) {
      Logger.getInstance(FocusUtil.class).debug(e);
    }
    return null;
  }
public static @Nullable Component getMostRecentComponent(Component component, Window ancestor)