Dimension viewPref = view.getPreferredSize();
Dimension viewPref = new Dimension(view.getPreferredSize());
  public void layoutContainer(Container parent)   {    // The way to interpret this function is basically to ignore the names    // of methods it calls, and focus on the variable names here. getViewRect    // doesn't, for example, return the view; it returns the port bounds in    // view space. Likwise setViewPosition doesn't reposition the view; it     // positions the port, in view coordinates.    JViewport port = (JViewport) parent;        Component view = port.getView();        if (view == null)      return;    // These dimensions and positions are in *view space*.  Do not mix    // variables in here from port space (eg. parent.getBounds()). This    // function should be entirely in view space, because the methods on    // the viewport require inputs in view space.    Rectangle portBounds = port.getViewRect();    Dimension viewPref = view.getPreferredSize();        Point portLowerRight = new Point(portBounds.x + portBounds.width,                                     portBounds.y + portBounds.height);            // vertical implementation of the above rules    if (view instanceof Scrollable)      {        Scrollable sView = (Scrollable) view;        // If the view size matches viewport size, the port offset can        // only be zero.        if (sView.getScrollableTracksViewportWidth())          {            viewPref.width = portBounds.width;            portBounds.x = 0;          }        if (sView.getScrollableTracksViewportHeight())          {            viewPref.height = portBounds.height;            portBounds.y = 0;          }      }    // The scroll pane manages the view size itself.    if (! (port.getParent() instanceof JScrollPane) )      {        if (viewPref.width < portBounds.width)      viewPref.width = portBounds.width;        if (viewPref.height < portBounds.height)          viewPref.height = portBounds.height;      }    // If the view is larger than the port, the port is top and right    // aligned.        if (portLowerRight.x > viewPref.width)          portBounds.x = 0;        if (portLowerRight.y > viewPref.height)          portBounds.y = 0;    port.setViewSize(viewPref);    port.setViewPosition(portBounds.getLocation());  }