8

我正在寻找类似于 Android 的 GWT 的 Toast 通知的组件(我用谷歌搜索了足够长的时间,我知道有一个 Ext-GWT 有类似的东西,但我想避免使用外部库)。NotificationMole 似乎是我正在寻找的组件,并且该组件在 GWT 2.1 中可用。但是,当我尝试在我的应用程序中显示它时,它永远不会出现。有人用过这个组件吗?这是我如何使用它的示例:

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

2 回答 2

11

NotificationMole 必须先附加到 DOM 才能显示:

HasWidgets panel; // This can be any panel that accepts children.
NotificationMole nm = new NotificatioMole();
panel.add(nm);
// Setup the NotificationMole...
nm.show();
于 2011-02-08T17:55:56.163 回答
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);
}
于 2013-06-29T16:36:56.927 回答