code: @Override
      public Dimension getPreferredSize() {
          /*
           * The preferred size is calculated based on the current position of the
           * component in its animation sequence. If the Component is expanded, then
           * the preferred size will be the preferred size of the top component plus
           * the preferred size of the embedded content container. <p>However, if the
           * scroll up is in any state of animation, the height component of the
           * preferred size will be the current height of the component (as contained
           * in the currentHeight variable)
           */
          Dimension dim;
          if (!isAnimated()) {
              if (getContentPane().isVisible()) {
                  dim = getContentPane().getPreferredSize();
              } else {
                  dim = super.getPreferredSize();
              }
          } else {
              dim = new Dimension(getContentPane().getPreferredSize());
              if (!getContentPane().isVisible() && currentHeight != -1) {
                  dim.height = currentHeight;
              }
          }
          return dim;
      }
docs: The critical part of the animation of this <code>JCollapsiblePane</code>
  relies on the calculation of its preferred size. During the animation,
  its preferred size (specially its height) will change, when expanding,
  from 0 to the preferred size of the content pane, and the reverse when
  collapsing.
  
  @return this component preferred size