Is there any way to create something similar to Javascript's alert in GWT?
Hi is there any way to create something si开发者_开发问答milar 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.
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.
You could use the PopupPanel.
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>
精彩评论