how to find out if the (text) contents of a label widget spans multiple lines?

2 views
Skip to first unread message

joster

unread,
Sep 26, 2007, 4:56:04 PM9/26/07
to Google Web Toolkit
Hello-

I have several Label widgets, some of which have long (long) text.
Text which are long (say beyond 4-5 words) is getting broken into
multiple lines.

Given a Label widget, how can I find out if its contents (text
associated with the Label widget) spans multiple lines?

Thanks.

Joster

mP

unread,
Sep 26, 2007, 5:34:35 PM9/26/07
to Google Web Toolkit
Label.getText.

The fact the words are broken over one or more lines doesnt matter.
The lot is inside the div span that is the Label widget.

joster

unread,
Sep 26, 2007, 5:48:13 PM9/26/07
to Google Web Toolkit
Hi-

Thanks. I am able to get the text inside a label.

For my specific case, I do need to find out if the words inside a
label are broken over one more more line - as i need to align labels
horizontally in a vertical panel.

Joster

mP

unread,
Sep 26, 2007, 5:57:02 PM9/26/07
to Google Web Toolkit
You cant without a lot of pain and anguish.

joster

unread,
Sep 26, 2007, 6:00:35 PM9/26/07
to Google Web Toolkit
I guess, I am ready to take the pain - can you outline the steps for
how I might go about doing this?

See picture about the mis-alignment issue here:
http://groups.google.com/group/Google-Web-Toolkit/attach/21188d34aaa85f51/dualtree.png?part=4&view=1

Reinier Zwitserloot

unread,
Sep 27, 2007, 11:52:34 AM9/27/07
to Google Web Toolkit
Basically, you use getClientWidth and getClientHeight (which are DOM.*
methods though there might be something 'better', DOM.* is pretty low
level and comes with no guarantees that it works on all browsers so
you best have a godo testing regime!). These methods tell you how
large any given element is. However, there are a metric arseload of
caveats, which is where the pain that mP described comes from.

1. Browsers don't exactly show a paragon of cooperation on this one.
Whether the sizes you get include borders and all that jazz is
certainly something you'll need to test.

2. A newly created DOM element doesn't really have any properties set
right. You'll need to add it to something which is added (to something
which is added to * infinity) which is added to the RootPanel somehow,
AND you need to 'wait a while' for this DOM element to really really
'become'. Usually a DeferredCommand will do the trick. This does mean
you'll need to do all your layouting, then in a deferredcommand check
the sizes, and if they aren't what you expected, do it all over again.
Tricky.

3. This works properly only on block-layouted elements. If you don't
know what it means, you better read up, but oversimplifying: spans, a
href, and other text-like tags are 'inline' displayed, whereas divs,
p, table, and other somewhat 'bigger' stuff is block layouted. Every
raw GWT widget is block layout, even label (which is a <div> under the
hood, and divs are default block layouted). You can change the
layouting using the CSS display: block;. This one is relevant mostly
if you're using a lot of HTML or HTMLPanel widgets.

On Sep 27, 12:00 am, joster <joster.j...@gmail.com> wrote:
> I guess, I am ready to take the pain - can you outline the steps for
> how I might go about doing this?
>

> See picture about the mis-alignment issue here:http://groups.google.com/group/Google-Web-Toolkit/attach/21188d34aaa8...

joster

unread,
Sep 27, 2007, 12:01:45 PM9/27/07
to Google Web Toolkit
Thanks mP and Reinier. I did solve my problem by using getClientWidth
and getClientHight to align labels.

Great!

Joster

Reply all
Reply to author
Forward
0 new messages