Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

2d String in a Box

Thread view: 
mainpayne - 20 Nov 2003 12:53 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.