Search code examples
javagraphics2drectangles

Rotate graphics2d around specific point


I would like to rotate my rectangle aroung its center. But when I use graphics2D it rotates around point, which is somewhere else. How can I rotate graphics2D around its center or is there any alternative to rotate rectangle?


Solution

  • Use the translate() method to center the rotaion wherever you need it. Make sure to store the Transformation getTransform() and after processing restore it.