I know how to rotate the image but how would I rotate the acctual Objet? I can't use g2d.rotate();
because I have multiple things drawn with the paint()
method and I only wan't one of the to rotate.
Asked
Active
Viewed 86 times
0

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
1For better help sooner, post an [SSCCE](http://sscce.org/). Note it is possible to rotate a `Graphics` for one object, then rotate it back for everything else. – Andrew Thompson Apr 28 '13 at 05:18
-
1@AndrewThompson: IIUC, you can save & restore the transform, as shown [here](http://stackoverflow.com/a/9373195/230513). – trashgod Apr 28 '13 at 06:33
-
@Fiskpotatis accept answers if they've helped you by clicking the check mark to the left of the answer. – Nico May 06 '13 at 20:56
2 Answers
1
- Since yours is a Swing application, you don't want to draw in the
paint(...)
method but rather in thepaintComponent(...)
method of a JComponent-derived class. - To rotate a single object consider creating a copy of your Graphics object by calling
create()
on the original, callingrotate(...)
on the new Graphics instance, drawing the rotated item with the new Graphics2D instance, and then disposing the copied Graphics object.

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
1
You can transform images with the java.awt.geom.AffineTransform class or implement your own rotation matrix.
Rotating an actual object implies you know its current location, orientation and pivot point. Rotation matrix is the solution.

Slihp
- 763
- 5
- 12