GWT Handler to SplitLayoutPanel drag

自作多情 提交于 2019-12-02 06:26:25

I think, you can do it by overriding onResize() inherited method of DockLayoutPanel:

  SplitLayoutPanel splitLayoutPanel = new SplitLayoutPanel(){
            @Override
            public void onResize() {
                super.onResize();
                Window.alert("resized");
            }
        };  

You can do this by adding intermediate ResizeLayoutPanels.

MyComposite.ui.xml :

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui" 
    xmlns:my="urn:import:my.custom.package.client">

<g:SplitLayoutPanel ui:field="splitLayoutPanel">
    <g:west size="250">
    <g:ResizeLayoutPanel ui:field="leftMenuOuterPanel">
            <my:MenuWidget ui:field="menuWidget" />
        </g:ResizeLayoutPanel>
    </g:west>
    <g:center>
        <g:ResizeLayoutPanel ui:field="centerOuterPanel">
            <my:AwesomeWidget ui:field="centerWidget" />
        </g:ResizeLayoutPanel>
    </g:center>
</g:SplitLayoutPanel>

</ui:UiBinder>

MyComposite.java :

class MyComposite extends Composite{
    // fuss with ui binder interfaces
    // other fuss to declare widgets as @UiField

    public MyComposite(){
        initWidget(uiBinder.createAndBindUi(this));
        leftMenuOuterPanel.addResizeHandler(new ResizeHandler(){
            public void onResize(ResizeEvent event){
                // Here do what you want
            }
        });
    }
}

I would recommend using a deferred command to do what you want with the resize event, because it fires a lot of times when dragging the splitter.

I use this to store the width of the menu panel in the user's preferences.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!