Dimension extents = vp.getExtentSize(); if (extents.width != hsb.getModel().getExtent() || extents.height != vsb.getModel().getExtent())
    public void stateChanged(ChangeEvent event)    {      JViewport vp = scrollpane.getViewport();      JScrollBar hsb = scrollpane.getHorizontalScrollBar();      JScrollBar vsb = scrollpane.getVerticalScrollBar();      Dimension extents = vp.getExtentSize();      if (extents.width != hsb.getModel().getExtent()          || extents.height != vsb.getModel().getExtent())        syncScrollPaneWithViewport();    }