| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Rate Thread | Display Modes |
|
|
#1 (permalink) |
|
Member
Join Date: Apr 2007
Location: Right now in Chennai
Posts: 30
Thanks: 5 Thanked 5 Times in 3 Posts Thanks: 5
Thanked 5 Times in 3 Posts
Rep Power: 2
|
How can I possibly right align a text using drawString method
Hello,
How can I possibly right align a text using drawString method with the given length of a text to display? Thanks in advance. |
|
|
|
|
|
#2 (permalink) |
|
Member
Join Date: Feb 2007
Location: 255.255.255.255
Posts: 86
Thanks: 0 Thanked 6 Times in 6 Posts Thanks: 0
Thanked 6 Times in 6 Posts
Rep Power: 3
|
Re: How can I possibly right align a text using drawString method
To use alignments etc. you would have to use the LayoutManagers.
But you are using drawString() method which paints on the cordinates that are specified. All you are doing is painting to a screen, there is no alignment for painting... |
|
|
|
| The Following User Says Thank You to live_wire For This Useful Post: |
ananthkolli (31-07-07)
|
|
|
#3 (permalink) |
|
Super Moderator
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117 Thanked 241 Times in 198 Posts Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51
|
Re: How can I possibly right align a text using drawString method
I agree with live_wire. But we can come up with a work around for this problem.
First calculate the length of the string and how many pixels each character will take. Based on this, arrange your string position. i.e., if L is the total available length, and X is number of pixels for each character and if you have N characters to be placed or painted, formula to find the starting point looks like this. Startpoint = L - (N*X) Hope it helps you to some extent. If you find any other solution, please let us know. Here, I am not handling the case where starting point goes negative. But solving it is not an issue. Thanks, Krishna
__________________
Give 1 cup rice to a hungry Indian just by a mouse click. No money, no form filling, no hassle... Click here for the donation. |
|
|
|
| The Following User Says Thank You to sk_kireeti For This Useful Post: |
ananthkolli (31-07-07)
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ejb | bujjimadhu | JAVA Technologies | 4 | 10-09-06 10:15 PM |
| java JSP | naga | JAVA Technologies | 4 | 21-08-06 05:03 PM |
| CA | vista | Other Queries | 2 | 14-04-06 02:49 AM |
| JAVA collection | naga | JAVA Technologies | 0 | 21-02-06 06:01 AM |
| JAVA PART3 | naga | JAVA Technologies | 0 | 18-02-06 07:48 AM |