【发布时间】:2019-06-02 11:50:38
【问题描述】:
我一直在尝试使布局居中,但由于某种原因它只能居中一点(可能大约 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());
}
【问题讨论】:
-
您使用的是什么版本的 Vaadin?您是否尝试在
buttons上使用setComponentAlignment()而不是vLayout? (我认为您需要为buttons的所有 4 个子组件执行此操作。)如果这不是您所需要的,请更详细地说明您想要做什么以及您目前拥有什么。 -
你确定按钮布局没有居中?也许按钮布局的内容根本没有居中。您在哪里对齐和调整按钮布局的内容?
-
@Cashbee 是的,这行得通,必须将每个按钮单独居中,谢谢!