public static @Nullable JComponent mergeComponentsWithAnchor(@NotNull Collection<? extends PanelWithAnchor> panels, boolean visibleOnly) {
    JComponent maxWidthAnchor = null;
    int maxWidth = 0;
    for (PanelWithAnchor panel : panels) {
      if (visibleOnly && (panel instanceof JComponent) && !((JComponent)panel).isVisible()) {
        continue;
      }
      JComponent anchor = panel != null ? panel.getOwnAnchor() : null;
      if (anchor != null) {
        panel.setAnchor(null); // to get own preferred size
        int anchorWidth = anchor.getPreferredSize().width;
        if (maxWidth < anchorWidth) {
          maxWidth = anchorWidth;
          maxWidthAnchor = anchor;
        }
      }
    }
    for (PanelWithAnchor panel : panels) {
      if (panel != null) {
        panel.setAnchor(maxWidthAnchor);
        if (panel instanceof JComponent) {
          ((JComponent)panel).revalidate();
          ((JComponent)panel).repaint();
        }
      }
    }
    return maxWidthAnchor;
  }
public static @Nullable JComponent mergeComponentsWithAnchor(@NotNull Collection<? extends PanelWithAnchor> panels, boolean visibleOnly)