Within a vanilla GWT project the easiest way to go about getting this is to use the layout panel classes - these use the RequiresResize
and ProvidesResize
interfaces you mentioned. The best way to get this started then is not with RootPanel
, but with RootLayoutPanel
. This alternative starting point wraps a single RootPanel
instance, and will size its child to the available browser space, by invoking RequiresResize.onResize
if it exists.
The rest of your widget tree (children added to parents, etc) then should also use these interfaces to declare that they need resize information. It is very likely that you won't actually end up building any widgets that don't, but mostly wrapping existing ones (with UiBinder or Composite) into a new widget - the trick there is that you are making a new widget, and by default one that doesn't implement ProvidesResize
or RequiresResize
. Two basic solutions to that as you build out your app:
Implement these two interfaces. Then, in your onResize()
method, invoke onResize()
of the top-level widget that needs to know that its size has changed. This allows more control, but requires more explicit code to make sizing work. The easiest way to do this is to extend ResizeComposite
instead of Composite
. Or,
Don't extend a Widget (i.e. don't extend Composite
/ResizeComposite
/etc), but instead, implement IsWidget
. This will let you avoid adding a new Widget
type to the tree, and just group all of the widgets you are using into a type that happens to build and set them all up. This is my preferred option - it won't look like a widget, often easier to mock, etc. Now you need to have a asWidget()
method that returns the base of your widget structure - anything this is added to will talk directly to that (and call its onResize()
directly), letting you ignore the details of how they need to interact. This is my preferred option.