Button, HorizontalLayout and alignment with caption

When trying to set a button in HorizontalLayout, the button tends to be aligned with caption parts of other components in the layout rather than the component themselves. For example

 HorizontalLayout hl = new HorizontalLayout();
    h1.addComponent(new TextField("Test");
    h1.addComponent(new Button("Do Something");

will result into the button being aligned not in line with the text field but with its caption text.

How can one fix the alignment so that it is aligned with the Text Field?

You need to store the component in variable, so that you have a reference, e.g.

TextField tf = new TextField("Test);

Then apply hl.setComponentAlignment(tf,Alignment.BOTTOM_CENTER);

Do this for both your components in your layout, and they are aligned by the bottom. Study alternative Alginment.* options to find one fits your need.

Am Using Vaadin 8, setComponentAlignment is not working, then how to align the field.