JViewport mapViewPort = mapScrollPane.getViewport(); Rectangle viewRect = mapViewPort.getViewRect(); int absMidX = Math.max(0, Math.round(relativeMidX * mapView.getWidth()) - viewRect.width / 2); int absMidY = Math.max(0, Math.round(relativeMidY * mapView.getHeight()) - viewRect.height / 2); mapViewPort.setViewPosition(new Point(absMidX, absMidY));
    public void componentResized(ComponentEvent event) {        // This can currently only happen when the map changes size        String s = String.valueOf((int) (mapView.getZoom() * 100)) + "%";        zoomLabel.setText(s);    }