Problem with setComponentAlignment..

I’m trying to alignment test-alignment some buttons for educational purposes, but I can not alignment them as a want… I have set the size of everything with .setSizeFull();
But still, the bottomright-button does not get placed in the bottom right corner?? What have I missed? Is there anything else I have to do to get it working? I have tried with buttons and labels (and set the labels to undefined size) with no luck. I have also tried with HorizontalLayout and VerticalLayout with the same result…

My code:

public void init() {
setMainWindow(new Window(“Testlayout”));

	final GridLayout grid = new GridLayout(3,1);
	Button topleft = new Button("Top Left");
	grid.addComponent(topleft, 0,0);
	grid.setComponentAlignment(topleft, Alignment.TOP_LEFT);
	Button topcenter = new Button("Top Center");
	grid.addComponent(topcenter, 1,0);
	grid.setComponentAlignment(topcenter, Alignment.TOP_CENTER);
	Button bottomright = new Button("Bottom right");
	grid.addComponent(bottomright, 2,0);
	grid.setComponentAlignment(bottomright, Alignment.BOTTOM_RIGHT);


Try with setExpandRatio();


The problem is that you have an invalid layout configuration: 100% high layout inside undefined high layout.

There’s one default VerticalLayout inside each Window and Panel component with 100% x undefined size.

Change the last line in your code to getMainWindow().setContent(grid) (effectively changing the root layout of the window to the grid and not the default vertical layout) and everything should work as expected.

Ah, I thought I had missed something :slight_smile: thanks for your reply, will try this now…
If i want to change the default verticalLayout from undefined height to defined height (100%), how Can I do that? Is that possible? (if i dont want to set the content to the gridLayout…)

Thanks in advance!

You can either provide a new layout for the mainWindow via setContent(…) or you can set the height of the default layout with mainWindow.getContent().setHeight(“100%”);