static int getPreferredWidth(@Nullable Component component) {
    return component == null ? 0 : component instanceof WidthBasedLayout ? ((WidthBasedLayout)component).getPreferredWidth()
                                                                         : component.getPreferredSize().width;
  }
static int getPreferredWidth(@Nullable Component component)