Vadiraj
Vadiraj

Reputation: 103

GWT's SplitLayoutPanel : get resize notification

I have this requirement where I only have one large widget set inside SplitLayoutPanel on the North.

As soon as the panel is resized using the splitter, I should get a notification with the values - How much has been expanded or collapsed.

Is this possible?

Upvotes: 0

Views: 97

Answers (1)

Adam
Adam

Reputation: 5589

SplitLayoutPanel implements ProvidesResize interface. It means, that

(...) the implementing widget will call RequiresResize.onResize() on its children whenever their size may have changed.

So, if only your large widget set inside SplitLayoutPanel on the North implements RequiresResize, it will be notified that it's size may have changed.

The last thing you need is to get the new size. You can use getWidgetSize method.

Please, notice, that the size you'll get is just one dimension. For North pane it is height.


Simple example code:

final SplitLayoutPanel splitLayoutPanel = new SplitLayoutPanel();

@Override
public void onModuleLoad() {
    splitLayoutPanel.addNorth(new MyResizeWidget(), 100);
    RootLayoutPanel.get().add(splitLayoutPanel);
}

public class MyResizeWidget extends Button implements RequiresResize {
    public MyResizeWidget() {
        super("Hello!");
    }

    @Override
    public void onResize() {
        this.setText("Hello! " + splitLayoutPanel.getWidgetSize(this).toString());
    }
}

Upvotes: 2

Related Questions