开发者

GWT Label getting correct width

When I attac开发者_如何转开发hed a Label to an AbsolutePanel and write "label.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. I think this is because of padding or something like this. The height seems to be correct. Is there any reason for? I want to place the Label for Example at the center of the Panel, but therefore I have to know the real size of the Label.


You can only get the width of the div containing the text in your label - there's no great way to get the width of the text itself.

You could try setting the width of the label to 0, waiting a while, and then asking getOffsetWidth how wide the label ended up. The browser may set the div to the minimum width that still contains the text you want. Unfortunately, that'll get complicated with wrapping and overflow rules. You'll also always have to wait a frame to do your layout, which won't look good.

For centering a piece of text, the best solution is to use CSS. See http://www.w3.org/Style/Examples/007/center#text , and apply styles like those to your Label.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜