🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1066

Re: How calculate the length in pixels of a String

#1066
From: Joi Ellis [TeamB]
Date: Fri, 31 May 2002 12:46
37 lines
2417 bytes
Antonio <avazquez@winsoftsystems.com> wrote:
> Suppose the following sentences:

> String myText = new String("Hello world!");
> Font smallFont = new Font("SansSerif", Font.PLAIN, 6);
>    ..   ..
>    ..   ..
>    pageWidth = getXXX  <<<<<<<<<<<<(retrieve page width)
>    ..   ..
>  g2d.setFont(smallFont);
>  g2d.drawString(myText,pen.x,,pen.y);


> How can I get the pixels used by my text to center the line, because i don't
> know the pixel used by drawString to get a line like...

>                   g2d.drawString(myText, pen.x  + ((pageWidth -
> pixels_used_by_myText) / 2), pen.y)

> In windows 32 there are several API's to get the FontMetric....

> I will thank any piece of code
> --
> Antonio V�zquez
> avazquez@winsoftsystems.com

See here:
http://java.sun.com/docs/books/tutorial/uiswing/painting/drawingText.html



-- 
Joi Ellis (TeamB)               http://www.teamb.com/
No direct email, please.
For best results, post on news server newsgroups.borland.com!
Newsgroup Guidelines: http://www.borland.com/newsgroups/guide.html
Only posts which violate the rules in guide.html are subject to cancelation.
Technical Details
Message-ID: <3cf77093_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!news.tiscali.nl!news-out.nuthinbutnews.com!propagator-sterling!news-in.nuthinbutnews.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews!not-for-mail
References: <3cf768fb_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1089d0,15edc31994bc18d7
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-05-31 06:02:08 PST
Sender: Joi Ellis <joi@h-66-134-231-90.CHCGILGM.covad.net>
Message-ID: <3cf77093_2@dnews>
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: How calculate the length in pixels of a String
Newsgroups: borland.public.jbuilder.java.api
References: <3cf768fb_2@dnews>
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.2.19-6.2.7 (i686))
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 66.134.231.90
Date: 31 May 2002 05:46:12 -0700
X-Trace: dnews 1022849172 66.134.231.90 (31 May 2002 05:46:12 -0700)
Lines: 37
X-Authenticated-User: jellis
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!news.tiscali.nl!news-out.nuthinbutnews.com!propagator-sterling!news-in.nuthinbutnews.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews!not-for-mail