簡體   English   中英

GWT中的MessageBox

[英]MessageBox in GWT

如何在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();

您可以改用DialogBox。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM