如何在GWT中显示AJAX“消息框”?我知道我可以使用Window.alert()
函数,但这太丑陋/烦人了。是否有内置函数?
谢谢!
伊凡
答案 0 :(得分:9)
以下是自定义警报小部件的简单实现(将其修改为您想要的内容):
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;
}
并使用它(最后注意center()方法,它实际上显示了小部件):
CustomWidgets.alertWidget("Adding account failed",
"System failed to add this account. Please chceck your settings properly.").center();
答案 1 :(得分:1)
您可以改用DialogBox。