Code:
double oldZoom = drawPane.getZoomLevelAsDouble();
double oldLeft = drawPane.getScrollLeft();
double oldTop = drawPane.getScrollTop();
int drawPaneWidth = drawPane.getWidth();
int drawPaneHeight = drawPane.getHeight();
int newLeft = (int)((oldLeft/oldZoom + drawPaneWidth/oldZoom/2.0 - drawPaneWidth/newZoom/2.0)*newZoom);
int newTop = (int)((oldTop/oldZoom + drawPaneHeight/oldZoom/2.0 - drawPaneHeight/newZoom/2.0)*newZoom);
drawPane.setZoomLevel(newZoom);
drawPane.scrollTo(newLeft,newTop);
Leave a comment: