5

你知道那里是否有任何用于 GWT 的通知小部件,比如这里的这个?

http://demo.vaadin.com/sampler#NotificationHumanized

4

1 回答 1

9

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
            tmp.@com.google.gwt.sample.contacts.client.Notification::hide()();
            $wnd.onmousemove = null;
        }
    }-*/;
}
于 2011-05-17T20:14:26.313 回答