Show text in the middle of the page - Vaadin

I am studying vaadin and have a problem to show the text (label) in 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 you use TextField instead of Label, then everything is in order. So what's wrong with Label?

+4
source share
1 answer

The label width is 100% by default, so your label is centered, but it takes up all the horizontal free space. You can fix this by saying:

 c.setWidth(null); 

or

 c.setSizeUndefined(); 
+9
source

Source: https://habr.com/ru/post/1390054/


All Articles