Border vpBorder = sc.getViewportBorder(); if (vpBorder != null) { Insets i = vpBorder.getBorderInsets(sc); width += i.left + i.right; height += i.top + i.bottom; }
  public Dimension preferredLayoutSize(Container parent)   {    // Sun's implementation simply throws a ClassCastException if    // parent is no JScrollPane, so do we.        JScrollPane sc = (JScrollPane) parent;        Dimension viewportSize = viewport.getPreferredSize();    Dimension viewSize = viewport.getViewSize();        int width = viewportSize.width;        int height = viewportSize.height;    // horizontal scrollbar needed if the view's preferred width    // is larger than the viewport's preferred width    if (hsb != null && viewSize.width > viewportSize.width)          height += hsb.getPreferredSize().height;    // vertical scrollbar needed if the view's preferred height    // is larger than the viewport's preferred height    if (vsb != null && viewSize.height > viewportSize.height)          width += vsb.getPreferredSize().width;        if (rowHead != null && rowHead.isVisible())          width += rowHead.getPreferredSize().width;        if (colHead != null && colHead.isVisible())          height += colHead.getPreferredSize().height;    Insets i = sc.getInsets();    return new Dimension(width + i.left + i.right,                         height + i.left + i.right);      }