Hi,
I want to draw a string of varying size inside a box.
g.drawString("........string....", x, y)
g.drawBox(x, y, w, h);
-------
|String| h
-------
w
Is there a good way to calculate the size of the box?
Antti S. Brax - 20 Nov 2003 13:38 GMT
d97-akj@nada.kth.se wrote in comp.lang.java.gui:
> I want to draw a string of varying size inside a box.
<snip>
> Is there a good way to calculate the size of the box?
Look at the API documentation of Graphics class for methods
that have something to do with Fonts. Then look at the API
documentation of the classes that those methods return.
You should be able to find the answer yourself in about 5
minutes.

Signature
Antti S. Brax - asb(at)iki.fi Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
Roedy Green - 20 Nov 2003 20:16 GMT
>Is there a good way to calculate the size of the box?
see FontMetrics
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Antti S. Brax - 21 Nov 2003 07:40 GMT
roedy@seewebsite.com wrote in comp.lang.java.gui:
>>Is there a good way to calculate the size of the box?
>
> see FontMetrics
The bounding box returned by FontMetrics doesn't always contain
accents and such. TextLayout OTOH guarantees that the bounding
box it returns contains all the pixels in the text.

Signature
Antti S. Brax - asb(at)iki.fi Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/