Article View: borland.public.jbuilder.java.api
Article #1064How calculate the length in pixels of a String
From: Antonio
Date: Fri, 31 May 2002 12:16
Date: Fri, 31 May 2002 12:16
24 lines
1738 bytes
1738 bytes
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
Technical Details
Message-ID:
<3cf768fb_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!londen1-snf1.gtei.net!nycmny1-snh1.gtei.net!news.gtei.net!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1089d0,15edc31994bc18d7,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-05-31 05:26:24 PST From: "Antonio" <avazquez@winsoftsystems.com> Newsgroups: borland.public.jbuilder.java.api Subject: How calculate the length in pixels of a String Date: Fri, 31 May 2002 14:16:12 +0200 Lines: 27 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 62.174.36.236 Message-ID: <3cf768fb_2@dnews> X-Trace: dnews 1022847227 62.174.36.236 (31 May 2002 05:13:47 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!londen1-snf1.gtei.net!nycmny1-snh1.gtei.net!news.gtei.net!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews