【问题标题】:Cant center vertical layout不能居中垂直布局
【发布时间】: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 是的,这行得通,必须将每个按钮单独居中,谢谢!

标签: java alignment vaadin


【解决方案1】:

试试这个:

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());

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多