vasan_sr
asked on
Draw Text from Right
Hi Gurus,
In my Project i have to generate an Image. For this iam using com.sun.image.codec.jpeg.* ; In the image Iam drawing the text (request from a Jsp to a servlet.
I want to align the text from right to Left. Can any one explain How to draw the text from right to left in Java.
Thanks in advance
VasanS
In my Project i have to generate an Image. For this iam using com.sun.image.codec.jpeg.*
I want to align the text from right to Left. Can any one explain How to draw the text from right to left in Java.
Thanks in advance
VasanS
ASKER
HI,
Iam drawing an Arabic Text , so it has to align from right to left. I found the width of the text, also it is not alifning proper.
One more solution is there..ie by using TextLayout. Can u explain how to use text layout in drawing text from right to left
VasanS
Iam drawing an Arabic Text , so it has to align from right to left. I found the width of the text, also it is not alifning proper.
One more solution is there..ie by using TextLayout. Can u explain how to use text layout in drawing text from right to left
VasanS
Sorry haven't ever used TextLayout.
Since you draw on a Image, I assume that you have a Graphics object. All you have to do is to draw from right to left, starting with "image.width" coordinate, decreasing the drawing point with the last drawed character width, down to 0.
Or you can remap the coordinates from {x = 0, y = 0}={top left corner} to {top right corner}
Or you can remap the coordinates from {x = 0, y = 0}={top left corner} to {top right corner}
http://developer.java.sun.com/developer/onlineTraining/Media/2DText/int.html
This will help you
Tijo
This will help you
Tijo
ASKER
Dear Ovi,
can u be more clear.How to drawString from right to left. Only we can give the x & Y co-ordinates and it will paint from that co-ordinalte..
I want to paint from the right to left. Can u explain more. If u explain with example i will be more happy.
VasanS
can u be more clear.How to drawString from right to left. Only we can give the x & Y co-ordinates and it will paint from that co-ordinalte..
I want to paint from the right to left. Can u explain more. If u explain with example i will be more happy.
VasanS
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you just want to right align, then you need to use FontMetrics to calculate the width of your text and draw it such that the last char appears on the right edge.
If you actually want to draw your text from right to left, then simply reverse your string and right align as above.