How to get the size of a Label?

7 views
Skip to first unread message

ph09

unread,
Sep 6, 2011, 1:42:41 PM9/6/11
to Google Web Toolkit
Hey,

I want to get the Size of a label, but I always get 0.
Here is the Code:

Label label= new Label(".......");
rootLabel.setStyleName("gwt-Label-1");
int width = label.getOffsetWidth();

Is there anything wrong? I guess not...
With an Absolute Panel "getOffsetWidth()" works.

greets

Jeff Larsen

unread,
Sep 6, 2011, 2:49:11 PM9/6/11
to google-we...@googlegroups.com
the label needs to be attached before you're able to get the size. 

ph09

unread,
Sep 6, 2011, 5:23:31 PM9/6/11
to Google Web Toolkit
Ok, but when I attached the Label to the AbsolutePanel and do
"getOffsetWidth()", I get for Example
a width of 700px for the AbsolutePanel and a width of 698px for the
Label. Certainly the label is less smaller.
Is there any reason for? I want to place the Label at the center of
the Panel, but therefore I have to know the size of the Label.
Reply all
Reply to author
Forward
0 new messages