Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a text on the middle of the page - Vaadin

Tags:

java

gwt

vaadin

I'm learning vaadin and have a problem to show a text (label) on the middle of the page Can someone explain why this code does not work?

Window window=new Window();

VerticalLayout root=new VerticalLayout();
root.setSizeFull();

Label c=new Label("User name");
//TextField c=new TextField("User name");

root.addComponent(c);
root.setComponentAlignment(c, Alignment.MIDDLE_CENTER);

window.setContent(root);
setMainWindow(window);

If to use TextField instead of Label, then everything is fine. So what is wrong with Label?

like image 348
corsair Avatar asked Jan 18 '23 20:01

corsair


1 Answers

The width of a Label is 100% by default so your Label is centered but it takes all available space horizontally. You can fix this by saying:

c.setWidth(null);

or

c.setSizeUndefined();
like image 81
Henri Kerola Avatar answered Jan 28 '23 15:01

Henri Kerola