@Override
  public int getBaseline(int width, int height) {
    if (getClientProperty(USE_BASELINE_KEY) != Boolean.TRUE || myOrientation != SwingConstants.HORIZONTAL) {
      return super.getBaseline(width, height);
    }

    int componentCount = getComponentCount();
    List<Rectangle> bounds = myLayoutStrategy.calculateBounds(this);

    int baseline = -1;
    for (int i = 0; i < componentCount; i++) {
      Component component = getComponent(i);
      Rectangle rect = bounds.get(i);
      boolean isShown = component.isVisible()
                        && rect.width != 0 && rect.height != 0
                        && rect.x < width && rect.y < height;
      if (isShown) {
        int b = component.getBaseline(rect.width, rect.height);
        if (b >= 0) {
          int baselineInParent = rect.y + b;
          if (baseline < 0) {
            baseline = baselineInParent;
          }
          else {
            if (baseline != baselineInParent) {
              return -1;
            }
          }
        }
      }
    }

    return baseline;
  }
@Override
  public int getBaseline(int width, int height)