Solved

Draw Text from Right

Posted on 2002-04-08
8
445 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry haven't ever used TextLayout.
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:jose_tijo
Comment Utility
0
 
LVL 2

Author Comment

by:vasan_sr
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now