private @NotNull Dimension getOptimalSize() {
    int width = getPreferredWidth();
    int height = getPreferredHeight(width);
    return new Dimension(width, height);
  }
private @NotNull Dimension getOptimalSize()