2011-02-08 17 views
7

我正在尋找類似於GWT的Android Toast通知的組件(我谷歌搜索足夠長,我知道有一個類似的Ext-GWT,但我想避免外部庫)。看起來NotificationMole是我正在查找的組件,並且此組件在GWT 2.1中可用。但是,當我嘗試在我的應用中顯示它時,它永遠不會顯示。有沒有人使用過這個組件?下面是一個例子,我如何使用它:在GWT中使用NotificationMole

NotificationMole nm = new NotificationMole(); 
nm.setAnimationDuration(2000); 
nm.setTitle("Title"); 
nm.setHeight("100px"); 
nm.setWidth("200px"); 
nm.setMessage("Test message to be shown in mole"); 
nm.show(); 

回答

10

的NotificationMole必須附加到DOM之前可以顯示它:

HasWidgets panel; // This can be any panel that accepts children. 
NotificationMole nm = new NotificatioMole(); 
panel.add(nm); 
// Setup the NotificationMole... 
nm.show(); 
+0

謝謝,這是我的問題的解決方案。 – dstefanox 2011-02-09 09:20:21

0
private void tellUser(String what) 
{ 
    PopupPanel pop = new PopupPanel(true); 
    pop.setWidget(new Label(what)); 


    final PopupPanel p = pop; 

    RootPanel.get().add(pop); 

    pop.setPopupPositionAndShow(new PopupPanel.PositionCallback() { 
      public void setPosition(int offsetWidth, int offsetHeight) { 
      int left = (Window.getClientWidth() - offsetWidth)/2; 
      int top = (Window.getClientHeight() - offsetHeight)/2; 
      p.setPopupPosition(left, top); 
      } 
     }); 

    new Timer() { 
     @Override 
     public void run() 
     { 
     System.out.println("timer repeated"); 
     RootPanel.get().remove(p); 
     this.cancel(); 
     } 
    }.scheduleRepeating(2000); 
}