This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Centering Text  on image Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Centering Text  on image" Watch "Centering Text  on image" New topic
Author

Centering Text on image

Divya Guttikonda
Ranch Hand

Joined: Mar 09, 2005
Posts: 47
Hi,
I am using com.mullassery.imaging.Imaging package in my java program.I am overlaying a text on the image.But what i need is to center the text when overlaying.It can span to any number of lines so the problem is i cant specify the x and y co-ordinates.Does anybody know if there is any existing functionality to center the text.Please help.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

Never heard of it.
Using the J2SE packages, I've used Graphics to get the size of an image, then the FontMetrics class to determine the size of the string. Subtract the string size from the size of the image and divide by two. Of course, doing multiple lines requires some more calculations, but the information is all there in those two classes.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Centering Text on image
 
Similar Threads
How do I Center Align text using drawString?
Tomcat error??
Ordered List tag inside jsp
Centering the header of the columns in JTable
How to center a String within a JPEG?