2011-02-08 16 views
7

Szukałem komponentu podobnego do powiadomienia Toast systemu Android dla GWT (I googled wystarczająco długo i wiem, że istnieje Ext-GWT, który ma coś podobnego, ale chcę uniknąć zewnętrznych bibliotek). Wygląda na to, że NotificationMole jest komponentem, którego szukam i że ten komponent jest dostępny w GWT 2.1. Jednak gdy próbuję pokazać to w mojej aplikacji, nigdy się nie pojawia. Czy ktoś użył tego komponentu? Oto przykład, jak go używać:Używanie NotificationMole w GWT

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(); 

Odpowiedz

10

NotificationMole musi być dołączony do DOM, zanim można wykazać:

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

Dziękuję, było to rozwiązanie mojego problemu . – dstefanox

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); 
}