I have looked around the site and did not find the answer to my question. So any help is appreciated.
I want to use drawString
to write individual text strings that each end at the same distance from a point that is the center of a circle. The individual strings are offset from each other by an angle.
The following code snippet does draw the individual strings at a certain distance - 120 points - from the center of the circle:
public void paintComponent(Graphics g) {
Graphics2D g2 =(Graphics2D) g;
g2.setColor(Color.black);
Font font = new Font(null, Font.PLAIN, 14);
AffineTransform affineTransform1 = new AffineTransform();
affineTransform1.rotate(Math.toRadians(-75), 0, 0);
affineTransform1.translate(-120, 0);
Font rotatedFont1 = font.deriveFont(affineTransform1);
g2.setFont(rotatedFont1);
g2.drawString("text here", 400, 400);
AffineTransform affineTransform2 = new AffineTransform();
affineTransform2.rotate(Math.toRadians(-60), 0, 0);
affineTransform2.translate(-120, 0);
Font rotatedFont2 = font.deriveFont(affineTransform2);
g2.setFont(rotatedFont2);
g2.drawString("test", 400, 400);
AffineTransform affineTransform3 = new AffineTransform();
affineTransform3.rotate(Math.toRadians(-45), 0, 0);
affineTransform3.translate(-120, 0);
Font rotatedFont3 = font.deriveFont(affineTransform3);
g2.setFont(rotatedFont3);
g2.drawString("About this", 400, 400);
g2.dispose();
120 points from the center of the circle at 400, 400 is where each string begins. I want to draw each string so that it ends at a certain distance from the center of the circle, say 75 points.
It would be kind of a right justification for each string.
Is there a way with .drawString to do this?