Is there a way to create something similar to a Javascript warning in GWT?

Hi, is there a way to create something similar to Window.alert()in GWT? Basically, I wanted to configure the OK button Window.alert()to say something else, but as I explored, there is no way to configure alerts.

Thank.

+5
source share
3 answers

Window.alert () is already available in GWT. It opens its own dialog box, in which the OK button is localized in the browser locale. This warning field cannot be changed.

Use PopupPanel or DecoratedPopupPanel .

+14
source

I usually encode a common dialog box that is created once, and when I need it again, the html content and title are replaced. You can also add a combination of OK / Cancel buttons, all this is quite simple.

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

HTML content is something very simple, i.e.

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

All Articles