code: public static JScrollPane createVerticalScrollPane(
          final JComponent component)
      {
          JScrollPane scrollPane = new JScrollPane(component)
          {
              /**
               * Serial UID
               */
              private static final long serialVersionUID = -177913025197077320L;
  
              @Override
              public Dimension getPreferredSize() 
              {
                  Dimension d = super.getPreferredSize();
                  if (super.isPreferredSizeSet())
                  {
                      return d;
                  }
                  JScrollBar scrollBar = getVerticalScrollBar();
                  Dimension sd = scrollBar.getPreferredSize();
                  d.width += sd.width;
                  return d;
              }
              
              @Override
              public boolean isValidateRoot()
              {
                  return false;
              }
          };
          return scrollPane;
      }
docs: Creates a JScrollPane for vertically scrolling the given component.
  The scroll pane will take into account that the vertical scroll bar
  will be shown when needed, and return a preferred size that takes
  the width of this scroll bar into account, so that when the vertical
  scroll bar appears, the contained component can still have its
  preferred width.
  
  @param component The view component
  @return The scroll pane