斜面中心垂直布局

时间:2019-01-07 19:40:21

标签: java alignment vaadin

我一直在尝试使布局居中,但由于某种原因(也许约1厘米),它只会稍微居中。这是我的代码:

VerticalLayout vLayout = new VerticalLayout();
VerticalLayout buttons = new VerticalLayout(lHeader, merchantSearch, addMerchant, showMerchants);

public MainMenuView() {
    vLayout.setSizeFull();
    vLayout.addComponent(buttons);
    vLayout.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    this.setCompositionRoot(vLayout);

    addMerchant.setStyleName("mystyle");
    showMerchants.setStyleName("mystyle");
    merchantSearch.setStyleName("mystyle");
    lHeader.addStyleName("mylabelstyle");
    addMerchant.addClickListener(e -> addMerchant());
    showMerchants.addClickListener(e -> showMerchants());
    merchantSearch.addClickListener(e -> merchantSearch());

}

1 个答案:

答案 0 :(得分:0)

尝试一下:

VerticalLayout vLayout = new VerticalLayout();
VerticalLayout buttons = new VerticalLayout();

public MainMenuView() {

    buttons.addComponents(lHeader, merchantSearch, addMerchant, showMerchants);
    buttons.setComponentAlignment(lHeader, Alignment.MIDDLE_CENTER);
    buttons.setComponentAlignment(merchantSearch, Alignment.MIDDLE_CENTER);
    buttons.setComponentAlignment(addMerchant, Alignment.MIDDLE_CENTER);
    buttons.setComponentAlignment(showMerchants, Alignment.MIDDLE_CENTER);

    vLayout.setSizeFull();
    vLayout.addComponent(buttons);
    vLayout.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    this.setCompositionRoot(vLayout);

    addMerchant.setStyleName("mystyle");
    showMerchants.setStyleName("mystyle");
    merchantSearch.setStyleName("mystyle");
    lHeader.addStyleName("mylabelstyle");
    addMerchant.addClickListener(e -> addMerchant());
    showMerchants.addClickListener(e -> showMerchants());
    merchantSearch.addClickListener(e -> merchantSearch());

}