问题
Is it possible in GWT to had a handler that detects that the knob pf SplitLayoutPanel is been drag or pressed?
Thanks for the help.
回答1:
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");
}
};
回答2:
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.
来源:https://stackoverflow.com/questions/9735735/gwt-handler-to-splitlayoutpanel-drag