BoundedRangeModel vmod = vsb.getModel(); if (vmod != null) ypos = vmod.getValue();
Rectangle vr = vp.getViewRect(); Dimension vs = vp.getViewSize();  if (vsb != null && (vsb.getMinimum() != 0 || vsb.getMaximum() != vs.height || vsb.getValue() != vr.y || vsb.getVisibleAmount() != vr.height)) {      vsb.setValue(vr.y, vr.height, 0, vs.height); }  if (hsb != null && (hsb.getMinimum() != 0 || hsb.getMaximum() != vs.width || hsb.getValue() != vr.width || hsb.getVisibleAmount() != vr.height)) hsb.setValue(vr.x, vr.width, 0, vs.width);
  ChangeListener createScrollListener()  {    return new ChangeListener() {        public void stateChanged(ChangeEvent event)        {          int xpos = 0;          int ypos = 0;          JScrollBar vsb = JScrollPane.this.getVerticalScrollBar();          JScrollBar hsb = JScrollPane.this.getHorizontalScrollBar();                    if (vsb != null)            {              BoundedRangeModel vmod = vsb.getModel();              if (vmod != null)                ypos = vmod.getValue();            }          if (hsb != null)            {              BoundedRangeModel hmod = hsb.getModel();              if (hmod != null)                xpos = hmod.getValue();            }          if (JScrollPane.this.viewport != null)            JScrollPane.this.viewport.setViewPosition(new Point(xpos, ypos));        }      };  }