int width = Math.max(portBounds.width, viewMinimum.width); int height = Math.max(portBounds.height, viewMinimum.height); int x = Math.min(0, portBounds.width - width); int y = Math.min(0, portBounds.height - height);  vp.setViewPosition(new Point(x, y)); vp.setViewSize(new Dimension(width, height));
Point portLowerRight = new Point(portBounds.x + portBounds.width, portBounds.y + portBounds.height);   if (portBounds.height >= viewMinimum.height) { portBounds.y = 0; viewSize.height = portBounds.height; } else { viewSize.height = viewMinimum.height; int overextension = portLowerRight.y - viewSize.height; if (overextension > 0) portBounds.y -= overextension; }   if (portBounds.width >= viewMinimum.width) { portBounds.x = 0; viewSize.width = portBounds.width; } else { viewSize.width = viewMinimum.width; int overextension = portLowerRight.x - viewSize.width; if (overextension > 0) portBounds.x -= overextension; }  port.setViewPosition(portBounds.getLocation()); port.setViewSize(viewSize);
  public void layoutContainer(Container parent)   {    JViewport vp = (JViewport)parent;    Component view = vp.getView();    Rectangle portBounds = vp.getBounds();    Dimension viewMinimum = view.getMinimumSize();    int width = Math.max(portBounds.width,                          viewMinimum.width);    int height = Math.max(portBounds.height,                           viewMinimum.height);    int x = Math.min(0, portBounds.width - width);    int y = Math.min(0, portBounds.height - height);    // System.err.println(this + ".layoutContainer() : width = " + width + ", height = " + height);    vp.setViewPosition(new Point(x, y));    vp.setViewSize(new Dimension(width, height));	}