How adjust the Vaadin components' vertical alignment in a HorizontalLayout?
Asked Answered
M

2

5

I want to align the Button on the same line as the Text Fields. The item alignment has been set to Alignment.CENTER, but as you can see from the image, the vertical centers of the TextFields are lower due to the label on top of them.

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setAlignItems(FlexComponent.Alignment.CENTER);
    Div div = new Div(buttonAddPriceRange);
    horizontalLayout.add(spanneVon, spanneBis, div);

enter image description here

Mincing answered 8/5, 2021 at 6:18 Comment(0)
A
9

layout.setAlignItems(Alignment.BASELINE); allows you to align items by the baseline, that is with the bottom.

Textfield and button baseline aligned

HorizontalLayout hl = new HorizontalLayout(new TextField("hello"),
    new Button("world"));
hl.setAlignItems(Alignment.BASELINE);
add(hl);

Check out the great video Master Vaadin VerticalLayout and HorizontalLayout - layouts in Vaadin Flow to learn more.

Astonied answered 8/5, 2021 at 6:53 Comment(0)
R
4

Try ...

horizontalLayout.setAlignItems(FlexComponent.Alignment.BASELINE);

Reddick answered 8/5, 2021 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.