public static void scroll(JComponent c, Rectangle r, ScrollBias horizontalBias, ScrollBias verticalBias) {
    Rectangle visible = c.getVisibleRect();
    Rectangle dest = new Rectangle(r);

    if (dest.width > visible.width) {
      if (horizontalBias == ScrollBias.VIEWPORT) {
        // leave as is
      }
      else if (horizontalBias == ScrollBias.UNCHANGED) {
        if (dest.x <= visible.x && dest.x + dest.width >= visible.x + visible.width) {
          dest.width = visible.width;
        }
      }
      else {
        if (horizontalBias == ScrollBias.CENTER) {
          dest.x += (dest.width - visible.width) / 2;
        }
        else if (horizontalBias == ScrollBias.LAST) dest.x += dest.width - visible.width;

        dest.width = visible.width;
      }
    }

    if (dest.height > visible.height) {
      // same code as above in the other direction
    }

    if (!visible.contains(dest)) c.scrollRectToVisible(dest);
  }
public static void scroll(JComponent c, Rectangle r, ScrollBias horizontalBias, ScrollBias verticalBias)