public void scrollBy(int deltaX, int deltaY) {
if (getParent() instanceof JViewport) {
JViewport viewport = (JViewport) getParent();
Point oldViewPos = viewport.getViewPosition();
Point viewPos = new Point(oldViewPos.x, oldViewPos.y);
if (deltaX!=0){
viewPos.x += deltaX;
int maxX = getWidth() - viewport.getWidth();
viewPos.x = Math.min(viewPos.x, maxX);
viewPos.x = Math.max(viewPos.x, 0);
}
if (deltaY !=0){
viewPos.y += deltaY;
int maxY = getHeight() - viewport.getHeight();
viewPos.y = Math.min(viewPos.y, maxY);
viewPos.y = Math.max(viewPos.y, 0);
}
if (viewPos.equals(oldViewPos)) {
stopAutoScroll();
} else {
viewport.setViewPosition(viewPos);
}
}