public PrintComp() {
buildMainLayout();
setCompositionRoot(mainLayout);
addComponentHandlers();
}
private void addComponentHandlers() {
btnPrint.addClickListener(new ClickListener() {
private static final long serialVersionUID = 5928233469999895083L;
public void buttonClick(ClickEvent event) {
addData();
printwindow();
}
});
}
protected void addData() {
Table table = new Table(“The Brightest Stars”);
table.addContainerProperty(“Name”, String.class, null);
table.addContainerProperty(“Mag”, Float.class, null);
Object newItemId = table.addItem();
Item row1 = table.getItem(newItemId);
row1.getItemProperty(“Name”).setValue(“Sirius”);
row1.getItemProperty(“Mag”).setValue(-1.46f);
table.addItem(new Object{“Canopus”, -0.72f}, 2);
table.addItem(new Object{“Arcturus”, -0.04f}, 3);
table.addItem(new Object{“Alpha Centauri”, -0.01f}, 4);
for (int i = 5; i < 100; i++) {
table.addItem(new Object{“Item " + i, (float) i}, i);
}
table.setWidth(“300px”);
table.setPageLength(table.size());
table.setColumnAlignment(“Name”, Align.RIGHT);
table.setVisible(true);
vlPresen.addComponent(table);}
protected void printwindow() {
btnPrint.setVisible(false);
final Window window = new Window(“tables REPORT”);
window.setDescription(“Report window”);
window.setModal(true);
window.setId(“window”);
window.setSizeFull();
// window.setHeight(3000f, Unit.PIXELS);
window.setPositionX(5);
window.setPositionY(5);
// window.setScrollTop(10);
window.setDraggable(isAttached());
window.setContent(vlPresen);
getUI().addWindow(window);
JavaScript.getCurrent().execute(“setTimeout(function() {” + " print(); }, 1000);”);
}