I created vaadin application using eclipse IDE. Below show my default class.
package com.example.test;
import com.vaadin.Application;
import com.vaadin.ui.*;
public class TestApplication extends Application {
@Override
public void init() {
Window mainWindow = new Window("Test Application");
Label label = new Label("Hello Vaadin user");
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
}
After that I created Vaading CustomComponet using Visual User Interface Design in vaadin. Below show that code.
package com.example.test;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
public class Temp extends CustomComponent {
@AutoGenerated
private VerticalLayout mainLayout;
@AutoGenerated
private TextField TextField_1;
/**
* 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 Temp() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
}
@AutoGenerated
private VerticalLayout buildMainLayout() {
// common part: create layout
mainLayout = new VerticalLayout();
// top-level component properties
setHeight("-1px");
setWidth("100.0%");
// Label_2
Label Label_2 = new Label();
Label_2.setImmediate(false);
Label_2.setHeight("-1px");
Label_2.setWidth("100.0%");
Label_2.setCaption("Name");
mainLayout.addComponent(Label_2);
// TextField_1
TextField_1 = new TextField();
TextField_1.setImmediate(false);
TextField_1.setHeight("-1px");
TextField_1.setWidth("-1px");
mainLayout.addComponent(TextField_1);
return mainLayout;
}
}
Now I want to display my CustomCompont GUI (Temp.java) how can I do it. (How to run Temp.java file)
Thanks it’s working now. If I change same code layout option — vertical layout to Absolute Layout
package com.example.test;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
public class Temp extends CustomComponent {
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private TextField TextField_1;
/**
* 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 Temp() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
}
@AutoGenerated
private AbsoluteLayout buildMainLayout() {
// common part: create layout
mainLayout = new AbsoluteLayout();
// top-level component properties
setHeight("100.0%");
setWidth("100.0%");
// Label_2
Label Label_2 = new Label();
Label_2.setImmediate(false);
Label_2.setHeight("-1px");
Label_2.setWidth("100.0%");
Label_2.setCaption("Name");
mainLayout.addComponent(Label_2, "top:114.0px;left:42.0px;");
// TextField_1
TextField_1 = new TextField();
TextField_1.setImmediate(false);
TextField_1.setHeight("-1px");
TextField_1.setWidth("-1px");
mainLayout.addComponent(TextField_1, "top:98.0px;left:135.0px;");
return mainLayout;
}
}
Using
mainWindow.addComponent(new Temp()); this I couldn’t see same form display previously .
Probably a size related problem. AbsoluteLayout requires you to define the size and it looks like you are mixing relative heights and undefined heights in your application. Try to add “?debug” to the application URL and use analyze layouts to see what is wrong.
One way to fix it could be to change
mainWindow.addComponent(new Temp());
into
Temp temp = new temp();
temp.setSizeFull();
mainWindow.getContent().setHeight("100%");
mainWindow.addComponent(temp);