I posted this over on the normal group but hopefully I can get some useful responses here. I am attempting to use the new GWT LayoutPanels and unfortunately they are causing me some grief. We are using the layout panels (RootLayoutPanel, DockLayoutPanel, LayoutPanel, etc) to arrange the overall layout of the panel. Then, the children of one of these panels needs to know how big it is so that it can size one of its children properly to cause a scroll bar to appear. As far as I can tell, the only way to do this is by calling getOffsetWidth and getOffsetHeight. I know that these methods will return 0 if the widget is not attached but I am finding that in even putting the calls in onLoad, these methods are still returning 0. Clearly I don't understand when GWT and/or the browser figures out what the sizes of these layout panels are.
Below is a simplification of my problem. The widget added to the RootLayoutPanel cannot determine its size when it is attached to the DOM. I made sure the widget had something in it and to prove that it ends up with a size, I added the call to the deferred command to display the size again. If you simply replace "RootLayoutPanel" with "RootPanel" then it will output the full window width. What am I doing wrong here? final FlowPanel testWidget = new FlowPanel() { protected void onLoad() { int width = getOffsetWidth(); Window.alert("width=" + width); // Outputs "0" } }; testWidget.add(new Label("Something")); RootLayoutPanel.get().add(testWidget); Window.alert("width=" + width); // Outputs "0" DeferredCommand.add(new Command() { public void execute() { int width = testWidget.getElement().getOffsetWidth(); Window.alert("width=" + width); // Outputs non-zero } } The value of 0 comes from FF 3.6. IE6 has almost the same problem except that in the cases where FF returns 0, IE6 is returning 60 (presumably the default size of the label). In both cases, it returns the full Window width in the DeferredCommand. -- http://groups.google.com/group/Google-Web-Toolkit-Contributors