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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With