java – GWT中的MessageBox

如何在GWT中显示AJAX“消息框”?我知道我可以使用Window.alert()函数,但这太丑陋/烦人了.有内置功能吗?

谢谢!

伊凡

解决方法:

这是自定义警报小部件的简单实现(将其修改为您想要的):

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();
上一篇:c – 如何翻译qmessagebox中的按钮?


下一篇:c# – 在FormClosing方法中处理是/否/取消消息框中的取消按钮