If you are using plain Graphics , first type Graphics2D :
Graphics2D g2d = (Graphics2D)g;
To rotate an integer Graphics2D :
g2d.rotate(Math.toRadians(degrees));
The reset rotation (so that you only rotate one thing):
AffineTransform old = g2d.getTransform(); g2d.rotate(Math.toRadians(degrees));
Example:
class MyPanel extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; AffineTransform old = g2d.getTransform(); g2d.rotate(Math.toRadians(degrees));
source share