How to place Vaadin confirmdialog ok and cancel button in center

对着背影说爱祢 提交于 2019-12-13 01:53:13

问题


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.



来源:https://stackoverflow.com/questions/19583002/how-to-place-vaadin-confirmdialog-ok-and-cancel-button-in-center

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!