Skip
Skip

Reputation: 6521

How to draw rotated text inside of a GC

I doing some 2D drawing in a SWT GUI. For that I have a GC Object.

How can I draw rotatet text inside of an SWT Canvas?

Upvotes: 0

Views: 1649

Answers (2)

Axel
Axel

Reputation: 1

Baz's answer will move the text outside of the window. This is caused by rotating the complete coordiate system of the window. The follwoing solution rotate the text and position it to the coordiates x, y:

Transform tr = new Transform(display);
tr.translate(x,y);
tr.rotate(-90);
gc.setTransform(tr);
gc.drawText("Text", 0, 0);

Upvotes: 0

Baz
Baz

Reputation: 36884

This should do it:

Transform tr = new Transform(display);
tr.rotate(-90);
gc.setTransform(tr);

gc.drawText("Text", x, y);

Upvotes: 2

Related Questions