How to Align Vertical Layout in the Top Center of the Window

How to Align Vertical Layout in the Top Center of the Window. ie, I have (250px X 250px ) Vertical Layout, added in window (window.setContent((verticalLayout);). this is not in the center position.

Please anybody help me…

Ideally you’d do this in your css file, but you could always do this:

Create a layout explicitly (horizontal or vertical), set its width to 100%, and set it as the content of the top-level window. Then add your vertical layout to this other one and call setContentAlignment to center your vertical layout within the other one.

        VerticalLayout mainLayout = new VerticalLayout();
        mainLayout.setSizeFull();
        window.setContent(mainLayout);

        VerticalLayout myLayout = //....

        mainLayout.addComponent(myLayout);
        mainLayout.setComponentAlignment(myLayout, Alignment.TOP_CENTER);

Cheers,
Bobby

It is not aligned to the center because the width of the VerticalLayout is 100% by default.

If your layout is 250 px wide then you can center it by:

myLayout.setWidth("250px");
setComponentAlignment(myLayout, Alignment.TOP_CENTER);

i used Alignment.Top_CENTER and Alignment.BOTTOM_RIGHT and Alignment.TOP_RIGHT but can you guide me for margin how to use margin on label and TextField and button

shammy saini:
i used Alignment.Top_CENTER and Alignment.BOTTOM_RIGHT and Alignment.TOP_RIGHT but can you guide me for margin how to use margin on label and TextField and button

How did you use the alignment property can you post a sample code if possible.