MessageBox in GWT

How to show AJAX "Message Box" in GWT? I know I can use the function Window.alert(), but it is too ugly / annoying. Is there a built-in function for?

Thank!

Yvan

+3
source share
2 answers

Here is a simple implementation of a custom alert widget (change 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):

CustomWidgets.alertWidget("Adding account failed",
                "System failed to add this account. Please chceck your settings properly.").center();
+9
source

You can use DialogBox instead.

+1
source

Source: https://habr.com/ru/post/1793252/


All Articles