I have a composite which extends ResizeComposite
and has a DockLayoutPanel
as its root. I can stick it directly into RootLayoutPanel
and it works because DockLayoutPanel
ProvidesResize
.
However, I'm wanting to use the MVP facilities in GWT 2.2, and RootLayoutPanel
can't be passed to ActivityManager#setDiplay(AcceptsOneWidget)
(since it's a multi-widget container).
At first glance, ScrollPanel
appears to meet the dual requirement of implementing AcceptsOneWidget
and both ProvidesResize
and RequiresResize
.
But I am finding that when I put my widget into a ScrollPanel
, that it has a 'zero size', and I have to size it manually in order to see it, and I'm having trouble knowing what size to give it. I'd rather a Panel that didn't necessarily scroll.
You can add ProvidesResize
to any widget by implementing it yourself, which is relatively simple - you just pass along all of the resize notifications you get to every sub-child that RequiresResize
.
Alternatively, if you just want your panel to take up all of the available space, you might try setting the width and height on the ScrollPanel
to "100%"
.
Finally, here's my implementation of a LayoutPanel that AcceptsOneWidget
:
public class PanelForView extends LayoutPanel implements AcceptsOneWidget
{
IsWidget myWidget = null;
@Override
public void setWidget(IsWidget w)
{
if (myWidget != w)
{
if (myWidget != null)
{
remove(myWidget);
}
if (w != null)
{
add(w);
}
myWidget = w;
}
}
}
I've been using this in my commercial app for months without any problems, and it's easy to swap views in and out of it. Feel free to use this code yourself.
There will be a SimpleLayoutPanel in GWT 2.3, described as:
A simple panel that {@link ProvidesResize} to its one child.