Having problems with getOffsetWidth() accuracy?

24 views
Skip to first unread message

markww

unread,
Dec 20, 2012, 4:54:55 PM12/20/12
to google-we...@googlegroups.com
Hi,

I'm using firefox 17. I'm trying to measure the width of a FlowPanel instance. It seems to always be off by about 5 or 6 pixels. I'm doing it like this:

    FlowPanel fp = new FlowPanel();
    fp.getElement().getStyle().setProperty("maxWidth", 300);
    fp.getElement().getStyle().setProperty("fontSize", 18);
    fp.getElement().setInnerText("hello");

    RootPanel.get().add(fp);
    int width = fp.getOffsetWidth(); // <-- not accurate

Is this not the correct way to do it? Is there some additional layout pass that happens after adding a panel which alters its size?

Thanks

Jens

unread,
Dec 20, 2012, 6:03:42 PM12/20/12
to google-we...@googlegroups.com
The safest way to read this information is to read it inside a Scheduler.get().scheduleDeferred() command.

-- J.
Reply all
Reply to author
Forward
0 new messages