Beginner Help

Hey Guys,

I m very new to Vaadin. Just playing around with it. But not able to figure this out.

I have created a custom component java code by using Visual Designer as below:

package com.example.documentmanager;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.TabSheet;

public class MainForm extends CustomComponent {

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private GridLayout gridLayout_2;
	@AutoGenerated
	private TabSheet tabSheet_1;

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public MainForm() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// gridLayout_2
		gridLayout_2 = buildGridLayout_2();
		mainLayout.addComponent(gridLayout_2, "left:0.0px;");
		
		return mainLayout;
	}

	@AutoGenerated
	private GridLayout buildGridLayout_2() {
		// common part: create layout
		gridLayout_2 = new GridLayout();
		gridLayout_2.setImmediate(false);
		gridLayout_2.setWidth("600px");
		gridLayout_2.setHeight("600px");
		gridLayout_2.setMargin(false);
		
		// tabSheet_1
		tabSheet_1 = new TabSheet();
		tabSheet_1.setImmediate(false);
		tabSheet_1.setWidth("380px");
		tabSheet_1.setHeight("340px");
		gridLayout_2.addComponent(tabSheet_1, 0, 0);
		
		return gridLayout_2;
	}

}

Now , I m trying to use this component into my Application file in the init() method. I m not able to figure out the same. Below is my application file.

package com.example.documentmanager;

import com.vaadin.Application;  
import com.vaadin.ui.Window;

import com.vaadin.ui.TabSheet;


public class DocumentmanagerApplication extends Application 
{
	@Override
	public void init() 
	{
		Window mainWindow = new Window("Home Work 1");	
		MainForm form1 = new MainForm();
		
		/** Code for Tabsheet goes here */
		TabSheet Data_Table_TabSheet = new TabSheet();
		Data_Table_TabSheet.setSizeUndefined();
		Data_Table_TabSheet.addTab(null, "First Tab", null);
		
		//mainWindow.add;
		//mainWindow.addComponent(Data_Table_TabSheet);
		setMainWindow(mainWindow);
	}
}

Any inputs on this , would be helpful.

Thanks,
Sam.

Hi Sam,

You need to add your form component to the window before it is a part of your user interface. Your init() should look something like this:

@Override
public void init() {
	Window mainWindow = new Window("Home Work 1");
	setMainWindow(mainWindow);
	((VerticalLayout)mainWindow.getContent()).setSizeFull();

	MainForm form1 = new MainForm();
	mainWindow.addComponent(form1);
}

Note that you need also to set the main window default layout to full size (see line 5), because your form component is relatively sized. Otherwise the component will use the minimum amount of space which is zero.