Search code examples
gwtresizesplitpanel

GWT SplitLayoutPanel resize


I've a TabPanel which contains a SplitLayoutPanel with inside two ScrollPanel, one in the Center and one in the South edge of the dock. When I resize the browser window my SplitLayoutPanel doesn't resize automatically. I try to solve the problem with this code:

     Window.addResizeHandler(new ResizeHandler() {
            @Override
            public void onResize(ResizeEvent event) {
                    setSplitPanelSize();
            }
        });


protected void setSplitPanelSize() {
    if (getParent() != null) {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
            @Override
            public void execute() {
                mainSplitPanel.setSize(getParent().getOffsetWidth() + "px", getParent().getOffsetHeight() + "px");
            }
        });
    }

}

but using getParent() in order to retrieve TabPanel size is an unsafe soultion. Is there another way to resize SplitLayoutPanel (and its elements) on browser resizing?


Solution

  • SplitLayoutPanel implements RequiresResize and ProvidesResize as it extends from DockLayoutPanel. You can override the onResize() method to do what you wish. Also it may be necessary to call the base onResize() method as well in your override.