I have not tried this, but it seems that you are not getting the correct middle of the rectangle. Try:
AffineTransform transform = new AffineTransform(); transform.rotate(Math.toRadians(45), rectangle.getX() + rectangle.width/2, rectangle.getY() + rectangle.height/2); g2.fill(transformed);
The difference is that now you add the width to the starting point X and add the height to the starting point Y, and therefore to the middle of the rectangle.
Hope this helps.
Dan w source share