Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Top Margin in the page
Hi I am doing the following
public class SpringVaadinApplication extends Application implements ApplicationContext.TransactionListener {
public SpringVaadinApplication(String applicationTitle) {
body = new VerticalLayout();
resultsLayout = new VerticalLayout();
header = new VerticalLayout();
resultsLabel = new Label();
resultsTable = new UserResultsTable(); // Table with specific columns
orderResultsTable = new Table();
mainWindow = new Window(applicationTitle);
body.setSpacing(true);
body.setMargin(true);
body.setHeight("100%");
}
@Override
public void init() {
setTheme("runo");
initLayout();
}
/*
* First method thats called from init
*/
private void initLayout() {
// Set the scroll bar on the main window
mainWindow.setScrollable(true);
// Adding the body which is a vertical Layout to the mainWindow
mainWindow.addComponent(header);
mainWindow.addComponent(body);
// Add the results vertical layout to the mainWindow
resultsLayout.setSizeFull();
mainWindow.addComponent(resultsLayout);
// set the main Window
setMainWindow(mainWindow);
// Add the label which is the application title
header.addComponent(new Label("<h2>" + applicationTitle + "</h2>", Label.CONTENT_XHTML));
// Add a menubar
// header.addComponent(buildMenuBar());
header.addComponent(new BuildMenuBar(mainWindow, body, resultsLayout));
}
}
THis is resulting in the page as shown in the attachment. I want to move the label to the top a little bit. Not wasting any space/margin. I tried playing with the margin , spacing but no sucess. would appreciate if anyone can tell me.
// Add the label which is the application title
header.addComponent(new Label("<h2>" + applicationTitle + "</h2>", Label.CONTENT_XHTML));
I think that adds a bit of margin, as now you have first a label, and within it <h2>. both probably adds their own margins. Instead do:
Label titleLabel = new Label(applicationTitle);
titleLabel.addStyleName(Runo.LABEL_H2);
header.addComponent(titleLabel);
Now it is the label that has a h2 style, instead of being the a h2 inside the label - so one margin less. Doing titleLabel.addStyleName("h2"); is equivalent, but using references to the themefile is a better practice
Also, the main window has alaways an own layout within it, and that one has margins on by default. You can turn them off with:
mainWindow.getContent().setMargin(false);