I extended the Panel class and added a Form component and a HorizontalLayout - acting as a footer, which contains a Link and a Button. I am attempting to expand the HorizontalLayout to 100%, while allowing the Panel to shrink to it’s natural size. In short, I would like the footer to expand to the size of the Form. I haven’t been able to accomplish this though.
There are two divs created between the default content VerticalLayout and the HorizontalLayout footer. While the grandparent div expands to the full width of the default content Vertical layout, the parent div of the HorizontalLayout expands only to the natural width, preventing it from taking up the full width.
I have reproduced this issue with other components as well. It can be solved if I remove the undefined width from the panel (defaulting to 100%), or set it to an explicit width. However, this is not ideal as I would like it to vary with the length of the form field captions, which are multi-lingual.
Any suggestions are greatly appreciated.
Here is the relevant code from the extended Panel:
private void createContent()
{
// set up margins
((VerticalLayout) getContent()).setMargin(false,true,false,true);
// create form
final Form form = new Form();
form.setWriteThrough(false);
form.setInvalidCommitted(false);
// FieldFactory
form.setFormFieldFactory(new LoginFieldFactory());
form.setItemDataSource(loginItem);
// determines which properties are shown, and in which order:
form.setVisibleItemProperties(Arrays.asList(new String[] {
"username", "password"}));
// add form to layout
addComponent(form);
// add footer
HorizontalLayout footer = new HorizontalLayout();
footer.setWidth("100%");
footer.setSpacing(true);
footer.setStyleName("e-loginpanel-footer");
addComponent(footer);
// add forgot password link
final Link forgotPass = new Link();
forgotPass.setCaption("Forgot Password?");
footer.addComponent(forgotPass);
footer.setComponentAlignment(forgotPass, Alignment.MIDDLE_LEFT);
// add login button
final Button submit = new Button("Submit");
// TODO add handler
footer.addComponent(submit);
footer.setComponentAlignment(submit, Alignment.MIDDLE_RIGHT);
}
Here is the relevant code in the view:
// add login panel
loginPanel = new LoginPanel("Login");
loginPanel.setWidth(SIZE_UNDEFINED, 0);
mainLayout.addComponent(loginPanel);
mainLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);