Drawing Rotated Text - Java 2D Graphics

Java examples for 2D Graphics:Text

Description

Drawing Rotated Text

Demo Code

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

public class Main {

  public void main(String[] argv) {
    // Draw string rotated clockwise 90 degrees
    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 2.0);
    Graphics2D g2d = null;//from   ww  w. jav  a2 s.  c o  m
    g2d.setTransform(at);
    g2d.drawString("aString", 100, 100);

    // Draw string rotated counter-clockwise 90 degrees
    at = new AffineTransform();
    at.setToRotation(-Math.PI / 2.0);
    g2d.setTransform(at);
    g2d.drawString("aString", 100, 100);
  }
}

Related Tutorials