2011-02-08 33 views
7

Tôi đang tìm kiếm thành phần tương tự như thông báo Toast của Android cho GWT (Tôi đã google đủ lâu và tôi biết rằng có một Ext-GWT có thứ gì đó tương tự, nhưng tôi muốn tránh các thư viện bên ngoài). Có vẻ như NotificationMole là thành phần mà tôi đang tìm kiếm và thành phần này có sẵn trong GWT 2.1. Tuy nhiên, khi tôi cố gắng hiển thị nó trong ứng dụng của tôi, nó không bao giờ xuất hiện. Có ai sử dụng thành phần này không? Dưới đây là một ví dụ làm thế nào tôi sử dụng nó:Sử dụng NotificationMole trong 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(); 

Trả lời

10

Các NotificationMole phải được gắn liền với DOM trước khi nó có thể được hiển thị:

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

Cảm ơn bạn, đây là giải pháp của vấn đề của tôi . – 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); 
} 
Các vấn đề liên quan