Hamza Yerlikaya
Hamza Yerlikaya

Reputation: 49339

Java AffineTransform moving origin

I would like to move the origin from top left to bottom middle of the component? I have been playing with AffineTransform class could not get it to work?

Upvotes: 3

Views: 2731

Answers (1)

Clint
Clint

Reputation: 9058

You will need the height and width of the component that you are trying to draw. Assuming you are in the paint(Graphics g) method the simplest way is:

paint(Graphics g){

Graphics2D g2 =  (Graphics2D)g;

g2.translate( component.getWidth()/2.0, component.getHeight()/2.0);

//...

}

Upvotes: 4

Related Questions