2011-05-17 60 views

回答

8

AFAIK有核心GWT没有这样的小部件,但为什么不推出自己的:

public class DelayedPopup extends PopupPanel { 

    public DelayedPopup(String text, boolean autoHide, boolean modal) { 
     super(autoHide, modal); 
     setWidget(new Label(text)); 
    } 

    void show(int delayMilliseconds) { 
     show(); 
     Timer t = new Timer() { 
      @Override 
      public void run() { 
       DelayedPopup.this.hide(); 
      } 
     }; 

     // Schedule the timer to close the popup in 3 seconds. 
     t.schedule(3000); 
    } 
} 

这超出了我的头,因此它可能无法编译,但你的想法。

更新:

按评论,我添加通知,隐藏自身在移动鼠标:

public class Notification extends PopupPanel { 

    public Notification(String text) { 
     super(false, false); 
     setWidget(new Label(text)); 
    } 

    @Override 
    public void show() { 
     installCloseHandler(); 
     super.show(); 
    } 

    public native void installCloseHandler() /*-{ 
     var tmp = this; 
     $wnd.onmousemove = function() { 
      // edit the com.google.gwt.sample.contacts.client package 
      // to match your own package name 
      [email protected]::hide()(); 
      $wnd.onmousemove = null; 
     } 
    }-*/; 
} 
+0

我同意这应该很容易滚你自己。值得注意的是,与上面链接的链接似乎不使用计时器来解除通知。相反,它似乎在监听onMouseMove并在鼠标移动时立即开始解散。 – pohl 2011-05-17 20:26:44

+0

你说得对。通过鼠标移动隐藏通知的新版本更新后。 – 2011-05-17 21:04:05