java GWT 中的消息框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5051643/
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
MessageBox in GWT
提问by friedkiwi
How do I show a AJAX "Message Box" in GWT? I know I can use the Window.alert()
function, but that's too ugly/annoying. Is there a built-in function for?
如何在 GWT 中显示 AJAX“消息框”?我知道我可以使用该Window.alert()
功能,但这太丑陋/烦人了。有内置函数吗?
Thank you!
谢谢!
Yvan
伊万
回答by Xorty
Here is simple implementation of custom alert widget (modify it to what you want):
这是自定义警报小部件的简单实现(将其修改为您想要的):
public static DialogBox alertWidget(final String header, final String content) {
final DialogBox box = new DialogBox();
final VerticalPanel panel = new VerticalPanel();
box.setText(header);
panel.add(new Label(content));
final Button buttonClose = new Button("Close",new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
box.hide();
}
});
// few empty labels to make widget larger
final Label emptyLabel = new Label("");
emptyLabel.setSize("auto","25px");
panel.add(emptyLabel);
panel.add(emptyLabel);
buttonClose.setWidth("90px");
panel.add(buttonClose);
panel.setCellHorizontalAlignment(buttonClose, HasAlignment.ALIGN_RIGHT);
box.add(panel);
return box;
}
And use it like (note center() method at the end, it actually shows the widget):
并像使用它一样(注意最后的 center() 方法,它实际上显示了小部件):
CustomWidgets.alertWidget("Adding account failed",
"System failed to add this account. Please chceck your settings properly.").center();
回答by jgrabowski
You can use DialogBox instead.
您可以改用 DialogBox。