Next Newbie Question: Getting font metrics before it is drawn.

E

Ed Dana

If I have a string with the word "supercalifragilisticexpialodocius,"
how do I get it's height and width BEFORE I draw it?

I want to take the string and position it where I need it to be
(centered exactly within a box) based on the strings graphic width and
height.

Thanks again for any clues.

Ed.
 
S

Steve W. Jackson

Ed Dana <[email protected]> said:
If I have a string with the word "supercalifragilisticexpialodocius,"
how do I get it's height and width BEFORE I draw it?

I want to take the string and position it where I need it to be
(centered exactly within a box) based on the strings graphic width and
height.

Thanks again for any clues.

Ed.

Look at the FontMetrics class. The class itself is abstract, but you
can obtain one from numerous objects via the getFontMetrics() call. If
you're just about to draw it, I'll assume that you're going to have
access to the Graphics object on to which you're drawing, right? So
have a look there.

= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top