So. Let's say i use drawString() to draw a, well, a string obviously. Is there any possible way that i can see the anchor point of that being the center of the string rather than the top-left corner? This would allow me to move the arrow in reation to the center.
Asked
Active
Viewed 324 times
-1
-
1The title doesn't match the question – Breeze May 28 '16 at 07:49
-
Thanks, I am little low on coffee and little bit out of it. Hope that's better. – Azazel May 28 '16 at 07:50
-
Yes and no, but it will screw with a lot of other things. Look into Graphics#translate and AffineTransform. Generally speaking you should work by calculating an offset value instead – MadProgrammer May 28 '16 at 09:21
-
Thanks @MadProgrammer. I saw your answer on another question similar to this. :) which was very informative so thankyou. However, i am unable to access the graphic object in this case because its under a private variable in another class which i am unfortunately unable to edit therefore making it a little difficult. Thanks anyhow though, learned so much. :) – Azazel May 28 '16 at 09:37
-
How are you calling `drawString` thing? – MadProgrammer May 28 '16 at 10:12
-
I am assuming you meant then. But its through another method provided by the aforementioned class. – Azazel May 28 '16 at 10:21
-
1Possible duplicate of [How can I center Graphics.drawString() in Java?](http://stackoverflow.com/questions/27706197/how-can-i-center-graphics-drawstring-in-java) – rene Jan 14 '17 at 15:31
1 Answers
-1
This should be able to help you. A simple equation can get you the appropriate coordinates to simulate center aligned text.
-
1If you think that the question is already answered on Stack Overflow please flag it as a duplicate instead of linking to it in an answer or copying the answer. And, even more important: your answer should always answer the question, even when any reference or link becomes invalid. At the moment it does not, so it is not a valid answer – Breeze May 30 '16 at 07:05