If i want to get the bounds or the width of a string, is there a method in GWT or javascript?

2 views
Skip to first unread message

Javelin

unread,
Jun 6, 2007, 10:48:16 PM6/6/07
to Google Web Toolkit
As the font is described in the css, i don't know if there are the
method to get the width of a string, anyone help me?

thanks!

//Javelin

Message has been deleted

Robert Hanson

unread,
Jun 7, 2007, 8:10:29 AM6/7/07
to Google-We...@googlegroups.com
> If i want to get the bounds or the width of a
> string, is there a method in GWT or javascript?


No, there is no function, and it is pretty difficult to get that information by writing your own code.  You could possible estimate the width, by storing the width of each char in your code, and adding up the width of all chars in the string... but it will break if someone resizes the text in their browser.

Rob
http://roberthanson.name

Ian Bambury

unread,
Jun 7, 2007, 9:14:03 AM6/7/07
to Google-We...@googlegroups.com
Create a label
Set the background and foreground colour to your screen's background colour and the font etc to the same as the text you want to measure
Put the label in a horizontal panel
Add the horizontal panel to the root panel
Set the horizontal panel's z index behind everything else

Put the text in the label
Read the width with getOffsetWidth()
 
Ian
Reply all
Reply to author
Forward
0 new messages