Hi. I’m obviously new to Vaadin as my simple question indicates. I’m trying to understand how to best layout components on screen.
The main screen of the application I’m trying to build is a split panel. The bottom half of the split is a tabbed component while the top half is a series of columns laid out horizontally. I’ve created this layout successfully, but I can’t quite get the hang of how to make the components look correct.
Basically, I’d like the containers in the top and bottom of the split panel to fill to take up the entire space given to them (the idea is that the application, once completed, would be embedded by others into their sites, so I can’t hardcode sizes). And then the tab panel and the columns in each of these containers should also stretch to fill the available area.
I want to control the sizing through CSS, but I’ve failed miserably. I’d fall back to setting it in the code, but that is not ideal, and I have not gotten that to work the way I want either, though I have gotten slightly better results than with CSS alone.
The issue I’m having is that only the split panel is filling the available screen real estate. Everything else is taking up the minimum size instead of also stretching to fill the space, so I end up with a lot of “dead” space.
Here’s the simple code needed to re-create (more or less) what I’m running into:
Stick this in your main application class:
Window aWindow = new Window("test");
setMainWindow(aWindow);
SplitPanel aLayout = new SplitPanel(SplitPanel.ORIENTATION_VERTICAL);
aLayout.setWidth("100%");
aLayout.setHeight("100%");
aLayout.setFirstComponent(new Top());
aLayout.setSecondComponent(new Bottom());
aWindow.setContent(aLayout);
Now, here is the code for the Top and Bottom classes which represent the column-based component and the tabbed component that i’d like to stretch to fill out the halves of the split panel, but with no luck.
private class Top extends HorizontalLayout {
Top() {
addStyleName("top");
Panel aOne = new Panel();
aOne.addStyleName("one");
Panel aTwo = new Panel();
aTwo.addStyleName("two");
Panel aThree = new Panel();
aThree.addStyleName("three");
addComponent(aOne);
addComponent(aTwo);
addComponent(aThree);
}
}
private class Bottom extends Panel {
Bottom() {
addStyleName("bottom");
TabSheet aTab = new TabSheet();
aTab.addStyleName("ts");
Panel aFoo = new Panel();
aFoo.addStyleName("foo");
Panel aBar = new Panel();
aBar.addStyleName("bar");
Panel aBaz = new Panel();
aBaz.addStyleName("baz");
aTab.addTab(aFoo, "foo", null);
aTab.addTab(aBar, "bar", null);
aTab.addTab(aBaz, "baz", null);
setContent(aTab);
}
}
Lastly, the CSS. Mostly just to color the components so I can tell them apart and see if they are stretching as I would expect.
@import url(../reindeer/styles.css);
.v-generated-body {
/* full height layout does not need scrollable body;
avoids excess scrollbars if moving sub-window over the window area */
overflow:hidden;
}
.one, .two, .three {
width: 100%;
height: 100%;
border: black 1px solid;
background: red;
}
.foo, .bar, .baz {
width: 100%;
height: 100%;
background: green;
}
.top {
width: 100%;
height: 100%;
background: yellow;
}
.bottom {
width: 100%;
height: 100%;
background: blue;
}
.ts {
width: 100%;
height: 100%;
}
The intended result is that the tabbed component is the entire size of the bottom half of the split panel, and the components in it’s tab stretch to fill the remaining available area. The top part of the split panel should be filled completely by the three columns.
I would appreciate it if someone could point me at what I’m doing wrong here. I’m sure it’s something simple, but I’m just not seeing it.
Thanks for your time.