private static <T> T findInComponentHierarchy(@NotNull Component component, Function<? super @NotNull Component, ? extends @Nullable T> mapper) {
    T found = mapper.fun(component);
    if (found != null) {
      return found;
    }
    if (component instanceof JComponent) {
      for (Component child : ((JComponent)component).getComponents()) {
        found = findInComponentHierarchy(child, mapper);
        if (found != null) {
          return found;
        }
      }
    }
    return null;
  }
private static <T> T findInComponentHierarchy(@NotNull Component component, Function<? super @NotNull Component, ? extends @Nullable T> mapper)