java 有没有办法在 GWT 中创建类似于 Javascript 警报的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4167764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to create something similar to Javascript's alert in GWT?
提问by datauser
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.
嗨,有什么方法可以创建类似于Window.alert()
GWT 的东西吗?基本上我想自定义Window.alert()
“确定”按钮来说别的,但正如我研究的那样,没有办法自定义警报框。
Thanks.
谢谢。
回答by Peter Knego
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.
Window.alert()在 GWT 中已经可用。它打开一个本机对话框,其中包含由浏览器的语言环境本地化的 OK 按钮。此警告框无法更改。
Use PopupPanelor DecoratedPopupPanel.
回答by Alberto Zaccagni
You could use the PopupPanel.
您可以使用PopupPanel。
回答by Harald Schilly
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.
我通常编写一个通用对话框,该对话框创建一次,当我再次需要它时,html 内容和标题将被替换。您还可以添加确定/取消按钮组合,这一切都相当简单。
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.
HTML 内容非常简单,即
<div style="width: 500px; overflow: auto;">...</div>