Is there any way to create something similar to Javascript's alert in GWT?

爱⌒轻易说出口 提交于 2019-12-23 11:54:48

问题


Hi is there any way to create something similar to Window.alert() in GWT? Basically I wanted to customize the Window.alert()'s "Ok" button to say something else but as I researched there is no way to customize the alert boxes.

Thanks.


回答1:


Window.alert() is already available in GWT. It opens a native dialog box which contais OK button localized by the browser's locale. This alert box can not be changed.

Use PopupPanel or DecoratedPopupPanel.




回答2:


You could use the PopupPanel.




回答3:


I usually code a generic dialog box, that is created once and when I need it again the html content and title is replaced. You can also add a OK/Cancel button combination, this all is rather straightforward.

private DialogBox   dialog     = null;
private HTML        dialogHtml = new HTML();
public void onDialog(final String title, final String html) {
  if (dialog == null) {
    dialog = new DialogBox();
    dialog.getElement().getStyle().setZIndex(99);
    dialog.setWidth("500px");
    dialog.setGlassEnabled(true);
    dialog.setAnimationEnabled(true);
    dialog.setModal(true);
    VerticalPanel vp = new VerticalPanel();
    vp.add(dialogHtml);
    HorizontalPanel hp = new HorizontalPanel();
    hp.setWidth("100%");
    Button close = new Button("close");
    close.setWidth("200px");
    close.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        dialog.hide();
      }
    });
    hp.add(close);
    hp.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_CENTER);
    hp.getElement().getStyle().setMarginTop(40, Unit.PX);
    vp.add(hp);
    vp.setSpacing(10);
    dialog.add(vp);
  }
  dialogHtml.setHTML(html);
  dialog.setHTML(title); // the actual title
  dialog.show();
  dialog.center();
}

The HTML content is something very simple, i.e.

<div style="width: 500px; overflow: auto;">...</div>


来源:https://stackoverflow.com/questions/4167764/is-there-any-way-to-create-something-similar-to-javascripts-alert-in-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!