public void checkScroll()
  {
    // only do this if we are not zoomed out
    if (sampleWidth != zoomOutWidth) {
      
      // get the rectangle that defines the current view
      JViewport viewport = scrollSound.getViewport();
      Rectangle rect = viewport.getViewRect();
      int rectMinX = (int) rect.getX();
      int rectWidth = (int) rect.getWidth();
      int rectMaxX = rectMinX + rectWidth - 1;
      
      // get the maximum possible index
      int maxIndex = sound.getLength() - rectWidth - 1;
      
      // check if current position is outside viewing area
      if (currentPixelPosition < rectMinX ||
          currentPixelPosition > rectMaxX) {
        
        // calculate how to position the current position in the middle of the viewing
        // area
        int barXPos = currentPixelPosition - (int) (rectWidth / 2);
        int barYPos = (int) (sampleHeight - rect.getHeight()) / 2;
        
        // check if the barPos is less than 0 or greater than max
        if (barXPos < 0)
          barXPos = 0;
        else if (barXPos > maxIndex)
          barXPos = maxIndex;
        
        // move the viewport upper left point
        viewport.setViewPosition(new Point(barXPos, barYPos));
      }
    }
  }