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 2005

Tip: Looking for answers? Try searching our database.

size of a string in pixel ?

Thread view: 
philippe.barthelemy@gmail.com - 26 Nov 2005 11:26 GMT
Hi,

In my graphic layout, i'd like to set the dimensions of the
string-based components.

the thing is that in order to preserve the layout, I'd like to set the
component's size to its maximum
( eg. if the JtextField contains a Date, i'll set it to the size
necessary to hold "wednesday, december 25th" )

in order to compute this size, I need to translate number of characters
to pixels. ( taking into account the fonts )

How can I do this ?

--Philippe
Andrey Kuznetsov - 26 Nov 2005 12:31 GMT
> the thing is that in order to preserve the layout, I'd like to set the
> component's size to its maximum
[quoted text clipped - 5 lines]
>
> How can I do this ?
see FontMetrics#stringWidth(String s);

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Christian Kaufhold - 26 Nov 2005 14:30 GMT
> In my graphic layout, i'd like to set the dimensions of the
> string-based components.
[quoted text clipped - 8 lines]
>
> How can I do this ?

getPreferredSize()

Christian
Roedy Green - 26 Nov 2005 16:27 GMT
>in order to compute this size, I need to translate number of characters
>to pixels. ( taking into account the fonts )

see http://mindprod.com/jgloss/font.html
http://mindprod.com/jgloss/fontmetrics.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



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



©2008 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.