title: Zoom in with affinetransform swing
body: <p>I'm working on my personal project using JAVA swing.</p>
  
  <p>The project is about drawing a map on a window.</p>
  
  <p><img src="https://i.stack.imgur.com/CyZYt.png" alt="enter image description here"></p>
  
  <p>The map is zoomable using affinetransform.
  The problem I'm having here is whenever I zoom in or out the map also shifts instead of zooming in/out on the point of the map that is at the center of the screen</p>
  
  <pre><code>private void updateAT()
  {
      Dimension d = panel.getSize();
      int panelW = d.width;
      int panelH = d.height;
  
      Rectangle2D r = regionList[0].get("Victoria").getShape().getBounds2D();
  
      scaleX = (panelW/r.getWidth()) * zoom;
      scaleY = (panelH/r.getHeight()) * zoom;
  
      AffineTransform goToOrigin = AffineTransform.getTranslateInstance(-r.getMinX(), -r.getMinY());
  
      AffineTransform pan = AffineTransform.getTranslateInstance(panX, panY);
  
      AffineTransform scaleAndFlip = AffineTransform.getScaleInstance(scaleX, -scaleY);
  
      //AffineTransform mirror_y = new AffineTransform(1, 0, 0, -1, 0, panelH);
  
      AffineTransform centre = AffineTransform.getTranslateInstance(panelW/2, panelH/2);
      centre.translate(-((r.getWidth()*scaleX)/2), ((r.getHeight()*scaleY)/2));
  
      world2pixel.setToIdentity();
      //world2pixel.concatenate(mirror_y);
      world2pixel.concatenate(pan);
      world2pixel.concatenate(centre);
      world2pixel.concatenate(scaleAndFlip);
      world2pixel.concatenate(goToOrigin);
  }
  </code></pre>