2d String in a Box  
Author Message
mainpayne





PostPosted: 2003-11-20 20:54:00 Top

java-programmer, 2d String in a Box 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?



 
asb





PostPosted: 2003-11-20 21:38:00 Top

java-programmer >> 2d String in a Box email***@***.com 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.

--
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/
 
asb





PostPosted: 2003-11-21 15:40:00 Top

java-programmer >> 2d String in a Box email***@***.com wrote in comp.lang.java.gui:
> On Thu, 20 Nov 2003 13:53:52 +0100, "mainpayne" <email***@***.com>
> wrote or quoted :
>
>>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.

--
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/