How to place Vaadin confirmdialog ok and cancel bu

2019-08-05 19:21发布

问题:

I have been using the ConfirmDialog add-on from the Vaadin Directory.

Is it possible to put the OK and Cancel buttons in the center of the window? By default it is in the right corner of the window.

回答1:

Just create a layout with buttons in the middle and set it as the content of ConfirmDialog. You can get the buttons using ConfirmDialog.get...Button(). Example:

    ConfirmDialog cd = ConfirmDialog.getFactory().create("Title", "", "OK",
            "Cancel");
    cd.setHeight("400px");
    cd.setWidth("400px");
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addComponent(cd.getCancelButton());
    buttons.addComponent(cd.getOkButton());
    VerticalLayout content = new VerticalLayout(buttons);
    content.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    content.setSizeFull();
    cd.setContent(content);
    cd.show(this, null, false);

However I agree with Jan that the good practice is having them in the bottom right corner.



回答2:

Keeping the buttons in the right lower corner is good practice when it comes to usability. Have a look at http://uxmovement.com/buttons/why-ok-buttons-in-dialog-boxes-work-best-on-the-right/ for more details. I would advice not to sacrifice behavior conventions for personal taste.



标签: vaadin