Solved

Draw Text from Right

Posted on 2002-04-08
8
454 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:vasan_sr
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6926962
Do you just want to right align your text, or do you actually want to draw the text from right to left (ie. first word appears on the right).

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.
0
 
LVL 2

Author Comment

by:vasan_sr
ID: 6927173
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
0
 
LVL 92

Expert Comment

by:objects
ID: 6927261
Sorry haven't ever used TextLayout.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 9

Expert Comment

by:Ovi
ID: 6927293
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}
0
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6927462
0
 
LVL 2

Author Comment

by:vasan_sr
ID: 6928197
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
   
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7933441
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7984219
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question