I'm not familiar with css, and unfortunately i dont have much time to investigate this so I've choosen build-in Vaadin ValoTheme
.
I have a verticallayout with two objects - label and panel, both components should be centered. This is what i'm trying to archieve:
Unfortunately, after enumorous attempts to make simlar, i got this
My code:
public class SplashScreen extends VerticalLayout implements View {
private static final int PANEL_WIDTH = 320;
private static final int PANEL_HEIGHT = 140;
private static final int BUTTON_WIDTH = 270;
private static final int BUTTON_HEIGHT = 70;
private ComponentHelper componentHelper;
private Panel panel;
private VerticalLayout formLayout;
private Label welcome;
private Button toLoginPage;
public SplashScreen() {
initComponents();
buildSplashView();
}
protected void initComponents() {
componentHelper = ComponentHelper.getInstance();
panel = componentHelper.createPanel("", PANEL_WIDTH, PANEL_HEIGHT);
welcome = componentHelper.createH3Label("Welcome");
formLayout = componentHelper.createVerticalLayout();
toLoginPage = componentHelper.createFriendlyButton("To Login Page", BUTTON_WIDTH, BUTTON_HEIGHT);
toLoginPage.addClickListener(this::redirect);
}
private void buildSplashView() {
addComponent(panel);
addComponent(welcome);
formLayout.addComponent(toLoginPage);
formLayout.setComponentAlignment(toLoginPage, Alignment.MIDDLE_CENTER);
panel.setContent(formLayout);
panel.setStyleName(ValoTheme.PANEL_BORDERLESS);
setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
setHeight(100, Unit.PERCENTAGE);
}
public void redirect(Button.ClickEvent event) {
try {
Thread.sleep(Constants.TRANSITION_TIME_DELAY);
getUI().getNavigator().navigateTo(ViewTokens.SIGNIN);
} catch (InterruptedException e) {
}
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
}
}
What i'm doing wrong? I can't fully understand how to design layouts properly( Before asking this question, i read Vaadin Book)
Note: 'componentHelper' intended for object creation with some minimal ValoTheme styling.
Thanks for suggestions
UPDATE: Result of using welcome.setSizeUndefined();
UPDATE 2: modified @qtdzz code to reproduce an issue:
private void buildSplashView() {
addComponent(welcome);
addComponent(text1);
addComponent(panel);
setComponentAlignment(welcome, Alignment.MIDDLE_CENTER);
setComponentAlignment(text1, Alignment.MIDDLE_CENTER);
setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
setSizeFull();
panel.setSizeUndefined();
panel.setContent(formLayout);
welcome.setSizeUndefined();
formLayout.addComponent(toLoginPage);
formLayout.setComponentAlignment(toLoginPage, Alignment.MIDDLE_CENTER);
formLayout.setSizeFull();
}
welcome.setSizeUndefined()
should make the alignment work – Keramic