Article View: borland.public.jbuilder.java.language
Article #14687How to know the string width in pixels
From: David Vásquez Estrada
Date: Fri, 13 Aug 1999 00:00
Date: Fri, 13 Aug 1999 00:00
53 lines
1714 bytes
1714 bytes
Hi, > Use the java.awt.FontMetrics class. And next time post your request to > borland.public.jbuilder.java.language Thank for the recomendation but the borland.public.jbuilder.java.language is too slow to download from my place. > > > ie: > > FontMetrics fm = new FontMetrics(Font f); The class FontMetrics is an abstract class; cannot be instantiated. There is method in the SwingUtilities class: SwingUtilities.computeStringWidth(FontMetrics, String); But again, it needs a FontMetrics instance. The only way is to extend this class. Then we must implement some required methods like the getWidth()...then we get the same problem. Am I wrong, or is there anoth David V�squez Estrada wrote in message <37B18BC5.FDC58523@ucbcba.edu.bo>... > >Hi, > > > >I�m trying to know the width in pixels of a string that will be the text > >of a JLabel. > >At this time I can know the number of characters and the current font > >size, but the result of: (number of characters * current Font size) is > >bigger than the required. > > > >Any suggestions? > > > >Thanks in advance > > > >David > >
Technical Details
Message-ID:
<37B447DD.A8A3FB9F@ucbcba.edu.bo>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f74b3,65a7d2b5fc13dd18,start X-Google-Attributes: gidf74b3,public From: David Vásquez Estrada <vasquezd@ucbcba.edu.bo> Subject: How to know the string width in pixels Date: 1999/08/13 Message-ID: <37B447DD.A8A3FB9F@ucbcba.edu.bo> X-Deja-AN: 512305135 Content-Transfer-Encoding: 8bit Organization: Another Netscape Collabra Server User X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language