Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created December 6, 2011 09:57
Show Gist options
  • Save dhavaln/1437617 to your computer and use it in GitHub Desktop.
Save dhavaln/1437617 to your computer and use it in GitHub Desktop.
Vaadin Sample application to set layout based on the Screen height and width
package com.example.vaadin_layout_test;
import com.vaadin.Application;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
public class Vaadin_layout_testApplication extends Application {
@Override
public void init() {
Window mainWindow = new Window("Vaadin_layout_test Application");
VerticalLayout vl = new VerticalLayout();
vl.setSizeFull();
mainWindow.setContent(vl);
mainWindow.addComponent(new Label("hi there"));
MenuBar mb = new MenuBar();
mb.addItem("test", null);
mainWindow.addComponent(mb);
Panel panel = new Panel();
panel.setSizeFull();
VerticalLayout vl1 = new VerticalLayout();
vl1.setSizeFull();
panel.setContent(vl1);
mainWindow.addComponent(panel);
Layout layout = addTable();
panel.addComponent(layout);
vl.setExpandRatio(panel, 1.0f);
setMainWindow(mainWindow);
}
public Layout addTable(){
VerticalLayout vl = new VerticalLayout();
vl.setSizeFull();
vl.addComponent(new Label("asdfasdf"));
vl.addComponent(new Label("asdfasdf"));
vl.addComponent(new Label("asdfasdf"));
vl.addComponent(new Label("asdfasdf"));
IndexedContainer container = new IndexedContainer();
for(int i=0;i<10;i++){
container.addContainerProperty(String.valueOf(i), String.class, "");
}
for (int i = 0; i < 1000; i++) {
Item item = container.addItem(i);
for(int j=0;j<10;j++){
item.getItemProperty(String.valueOf(j)).setValue(j);
}
}
Table table = new Table();
table.setContainerDataSource(container);
table.setSizeFull();
table.setPageLength(20);
vl.addComponent(table);
vl.setExpandRatio(table, 1.0f);
return vl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment