private static @NotNull Rectangle calcRectInParent(@NotNull Container child, @NotNull JComponent parent) {
    List<Container> chain = new ArrayList<>();
    Container container = child;
    while (container != parent) {
      chain.add(container);
      container = container.getParent();
      if (container == null) {
        throw new IllegalArgumentException("Source is not part of " + parent);
      }
    }

    Rectangle result = new Rectangle();
    parent.doLayout();
    for (int i = chain.size() - 1; i >= 0; i--) {
      Container c = chain.get(i);
      c.doLayout();
      result.x += c.getX();
      result.y += c.getY();
    }
    result.setSize(child.getSize());
    return result;
  }
private static @NotNull Rectangle calcRectInParent(@NotNull Container child, @NotNull JComponent parent)