2011-11-29 168 views
0

我的目標是僅在需要時才使用GWT.runSync加載彈出窗口內容。在onClickHandler中構建GWT彈出窗口不居中

如果你建造我的小部件:

public class CreateButton extends Button { 

public CreateButton() { 
    super("Create"); 
    buildUI(); 
} 

private void buildUI() { 

    final CreateWidget createWidget = new CreateWidget(); 

    final PopupPanel popupPanel = new PopupPanel(false); 
    popupPanel.setWidget(createWidget); 
    popupPanel.setGlassEnabled(true); 
    popupPanel.setAnimationEnabled(true); 
    addClickHandler(new ClickHandler() { 

     @Override 
     public void onClick(ClickEvent event) { 
      popupPanel.center(); 

     } 
    }); 
} 
} 

然後在彈出的將被正確居中。

如果我建立對clickHandler內彈出:

public class CreateButton extends Button { 

public CreateButton() { 
    super("Create"); 
    buildUI(); 
} 

private void buildUI() { 

     @Override 
     public void onClick(ClickEvent event) { 
      final CreateWidget createWidget = new CreateWidget(); 

      final PopupPanel popupPanel = new PopupPanel(false); 
      popupPanel.setWidget(createWidget); 
      popupPanel.setGlassEnabled(true); 
      popupPanel.setAnimationEnabled(true); 
      addClickHandler(new ClickHandler() { 

      popupPanel.center(); 

     } 
    }); 

} 
} 

彈出窗口將不能正確中心。我嘗試過使用setPositionAndShow,但是提供的偏移量是12,儘管CreateWidget實際上對於寬度和高度都是大約200px。

我想使用第二種方法,因此我最終可以在onClick中使用GWT.runAsync,因爲CreateWidget非常複雜。

我使用GWT-2.1.1

回答

0

似乎被延遲呼叫中心工作。也許一次關閉計時器也可以。當在GWT中包裝buildUI時,延遲呼叫也可以使用.runAsync

public class CreateButton extends Button { 

    public CreateButton() { 
     super("Create"); 
     buildUI(); 
    } 

    private void buildUI() { 

     @Override 
     public void onClick(ClickEvent event) { 
      final CreateWidget createWidget = new CreateWidget(); 

      final PopupPanel popupPanel = new PopupPanel(false); 
      popupPanel.setWidget(createWidget); 
      popupPanel.setGlassEnabled(true); 
      popupPanel.setAnimationEnabled(true); 
      addClickHandler(new ClickHandler() { 

       Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { 

        @Override 
        public boolean execute() { 

         popupPanel.center(); 
         return false; 

        } 
       }, 50); //a value greater than 50 maybe needed here. 
      });  
     } 
    } 

} 
} 
+0

您是否試過DeferredCommand? –