Emoagainst
Emoagainst

Reputation: 76

Calculate string width (in pixels) in GWT

I have a Label with very-very long string in it.

Method label.getOffsetWidth() returns 0 (I dont know why). But String is displayed.

How can i get Label (or String) width in pixels using GWT 2.4.0?

Upvotes: 3

Views: 6726

Answers (2)

Emoagainst
Emoagainst

Reputation: 76

Ok. I found answer for my question.
For be sure that Label have rendered use Scheduler.get().scheduleDeferred(Scheduler.ScheduledCommand cmd)

In @Override execute() call label.getElement().getClientWidth();

And that's it.

Upvotes: 2

barti_ddu
barti_ddu

Reputation: 10299

You could use getClientWidth() method of underlying DOM element to get its width in pixels:

label.getElement().getClientWidth();

see

Upvotes: 3

Related Questions