Component view = viewport.getView();   if (view == null) return;
  public void layoutContainer(Container parent)  {    // Sun's implementation simply throws a ClassCastException if    // parent is no JScrollPane, so do we.        JScrollPane sc = (JScrollPane) parent;            JViewport viewport = sc.getViewport();    Dimension viewSize = viewport.getView().getPreferredSize();            int x1 = 0, x2 = 0, x3 = 0, x4 = 0;            int y1 = 0, y2 = 0, y3 = 0, y4 = 0;            Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);            x1 = scrollPaneBounds.x;            y1 = scrollPaneBounds.y;            x4 = scrollPaneBounds.x + scrollPaneBounds.width;            y4 = scrollPaneBounds.y + scrollPaneBounds.height;            if (colHead != null)              y2 = y1 + colHead.getPreferredSize().height;            else              y2 = y1;            if (rowHead != null)              x2 = x1 + rowHead.getPreferredSize().width;            else              x2 = x1;            int vsbPolicy = sc.getVerticalScrollBarPolicy();            int hsbPolicy = sc.getHorizontalScrollBarPolicy();    int vsWidth = 0;    int hsHeight = 0;            boolean showVsb =               (vsb != null)              && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)                  || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED                   && viewSize.height > (y4 - y2)));        if (showVsb)      vsWidth = vsb.getPreferredSize().width;        // The horizontal scroll bar may become necessary if the vertical scroll    // bar appears, reducing the space, left for the component.                boolean showHsb =               (hsb != null)              && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)                  || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED               && viewSize.width > (x4 - x2 - vsWidth)));                if (showHsb)      hsHeight = hsb.getPreferredSize().height;        // If the horizontal scroll bar appears, and the vertical scroll bar    // was not necessary assuming that there is no horizontal scroll bar,    // the vertical scroll bar may become necessary because the horizontal    // scroll bar reduces the vertical space for the component.            if (!showVsb)      {        showVsb =           (vsb != null)          && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)              || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED                   && viewSize.height > (y4 - y2)));                    if (showVsb)          vsWidth = vsb.getPreferredSize().width;      }    x3 = x4 - vsWidth;    y3 = y4 - hsHeight;            // now set the layout            if (viewport != null)      viewport.setBounds(new Rectangle(x2, y2, x3 - x2, y3 - y2));            if (colHead != null)      colHead.setBounds(new Rectangle(x2, y1, x3 - x2, y2 - y1));            if (rowHead != null)      rowHead.setBounds(new Rectangle(x1, y2, x2 - x1, y3 - y2));            if (showVsb)              {                vsb.setVisible(true);        vsb.setBounds(new Rectangle(x3, y2, x4 - x3, y3 - y2));              }            else if (vsb != null)              vsb.setVisible(false);            if (showHsb)              {                hsb.setVisible(true);        hsb.setBounds(new Rectangle(x2, y3, x3 - x2, y4 - y3));              }            else if (hsb != null)              hsb.setVisible(false);            if (upperLeft != null)      upperLeft.setBounds(new Rectangle(x1, y1, x2 - x1, y2 - y1));            if (upperRight != null)      upperRight.setBounds(new Rectangle(x3, y1, x4 - x3, y2 - y1));            if (lowerLeft != null)      lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));            if (lowerRight != null)      lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));      }