I’m attempting to implement what Anna described (“in the latter”) and illustrated in this article:
http://www.cssreset.com/how-to-keep-footer-at-bottom-of-page-with-css/
I think I successfully applied this article’s technique to Vaadin 7 custom layout (page looks right and no layout errors in debugger)
@Theme(“mytheme”)
public class DemoUI extends UI {
@Override
protected void init(final VaadinRequest request) {
setContent(new Shell());
}
}
public class Shell extends CustomLayout {
public Shell() {
super("shell");
addStyleName("shell");
setSizeFull();
addComponent(new LoginComponent(), "content");
}
}
shell.html:
mytheme.css:
@import “…/reindeer/legacy-styles.css”;
html,
body {
margin:0;
padding:0;
height:100%;
}
.shell {
height:100%;
overflow: auto;
}
#wrapper {
min-height:100%;
position:relative;
}
#header {
padding:10px;
background:#5ee;
}
#content {
padding:10px;
padding-bottom:80px; /* Height of the footer element */
}
#footer {
width:100%;
height:80px;
position:absolute;
bottom:0;
left:0;
background:#ee5;
}
The only CSS addition that I made to the article was the addition of:
.shell {
height:100%;
overflow: auto;
}
As far as I can tell it is working, i.e. the footer stays at the bottom and browser window scrolls when necessary.
However there is one additional feature I would like in some situations I would like the content to expand
to fill the size of the browser. For example if there is a table in the center content I would like it to expand to
fill the space available to it.
public class LoginComponent extends VerticalLayout {
public LoginComponent() {
final Table table = new Table();
table.addContainerProperty("First Name", String.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);
for (int i = 0; i < 100; i++) {
table.addItem(new Object[] {
"Nicolaus","Copernicus",new Integer(1473 + i)}, new Integer(1 * i));
table.addItem(new Object[] {
"Tycho", "Brahe", new Integer(1546 + i)}, new Integer(2 * i));
table.addItem(new Object[] {
"Giordano","Bruno", new Integer(1548 + i)}, new Integer(3 * i));
table.addItem(new Object[] {
"Galileo", "Galilei", new Integer(1564 + i)}, new Integer(4 * i));
table.addItem(new Object[] {
"Johannes","Kepler", new Integer(1571 + i)}, new Integer(5 * i));
table.addItem(new Object[] {
"Isaac", "Newton", new Integer(1643 + i)}, new Integer(6 * i));
}
addComponent(table);
}
}
It’s pretty easy to do using the API (no CSS tricks necessary below) when the footer is always visible but I’m scratching my head
on how to make the table expand in the “footer on the bottom” layout I created.
Any advice?
Thanks
protected void init(final VaadinRequest request) {
full();
}
private void full() {
final VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSizeFull(); // to ensure whole space is in use
setContent(mainLayout);
final VerticalLayout header = new VerticalLayout();
Panel content = new Panel();
content.setSizeFull(); // to ensure the panel only takes the available space
final VerticalLayout footer = new VerticalLayout();
mainLayout.addComponent(header);
mainLayout.addComponent(content);
mainLayout.addComponent(footer);
mainLayout.setExpandRatio(content, 1); // to determine which component takes the excess space
final VerticalLayout contentLayout = new VerticalLayout();
contentLayout.setSizeUndefined(); // to ensure a scrollbar appears if the content won't fit otherwise
content.setContent(contentLayout);
header.addComponent(new Label("Header"));
footer.addComponent(new Label("Footer"));
contentLayout.setSizeFull();
final Table table = new Table();
table.addContainerProperty("First Name", String.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);
for (int i = 0; i < 100; i++) {
table.addItem(new Object[] {
"Nicolaus","Copernicus",new Integer(1473 + i)}, new Integer(1 * i));
table.addItem(new Object[] {
"Tycho", "Brahe", new Integer(1546 + i)}, new Integer(2 * i));
table.addItem(new Object[] {
"Giordano","Bruno", new Integer(1548 + i)}, new Integer(3 * i));
table.addItem(new Object[] {
"Galileo", "Galilei", new Integer(1564 + i)}, new Integer(4 * i));
table.addItem(new Object[] {
"Johannes","Kepler", new Integer(1571 + i)}, new Integer(5 * i));
table.addItem(new Object[] {
"Isaac", "Newton", new Integer(1643 + i)}, new Integer(6 * i));
}
contentLayout.addComponent(table);
contentLayout.setExpandRatio(table, 1.0f);
table.setSizeFull();
}