Align problem

I have this simple layout:

public class T extends HorizontalLayout {
    public T() {
        setSizeFull();
        setHeight("3em");

        Label label = new Label();
        addComponent(label);
        setComponentAlignment(label, Alignment.MIDDLE_LEFT);
        label.setCaption("Prompt");
        label.setSizeUndefined();
        
        TextField textField = new TextField();
        addComponent(textField);
        setExpandRatio(textField,1);
        textField.setSizeFull();
    }
}

The “Prompt” keeps at top-left corner and I want to center vertically with the text field.

Hi,

You are adding a caption to the Label, when you probably mean to add the content of the Label, which is set with method setValue(String), not with setCaption(). Then it should be aligned to middle with the TextField.
If you are building a form, you can also look into using
FormLayout
, where the caption of the TextField itself would aligned to the middle left fo the component.

  • Katri