How to center a component

Hi !

Is there a way (without CSS) to center (Horizontal & Vertical) a component on a screen.
Thanks !

Yes, something like:


		OrderedLayout l = new OrderedLayout();
		l.setSizeFull();
		Button centeredComponent = new Button("Foo");
		l.addComponent(centeredComponent);
		l.setComponentAlignment(centeredComponent,
				OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER,
				OrderedLayout.ALIGNMENT_VERTICAL_CENTER);
		Window w = new Window("My fancy app", l);
		setMainWindow(w);

layout.setAlign

Thanks a lot for your answer ! :smiley:

You can find more layout related tips and tricks from the developer site: http://dev.itmill.com/wiki/Articles/LayoutHowto

The list is currently quite small, but we’ll be adding these kind of little tips every once in a while.

-Jouni