Reputation: 285
hi all I'm having a strange problem, but I'm sure I'm doing something stupid. In a maven project I have my UI class as below:
package my.vaadin.project.exceptionTest;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@Theme("mytheme")
@Widgetset("my.vaadin.project.exceptionTest.MyAppWidgetset")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
final Calculation calculation = new Calculation();
final Label title = new Label("Calculation");
layout.addComponents(title, calculation);
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
And then I have another class which holds various fields that I then attempt to add to the UI, unsuccessfully:
package my.vaadin.project.exceptionTest;
import java.awt.Component;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.event.Action;
public class Calculation extends CustomComponent{
final VerticalLayout vl = new VerticalLayout();
final TextField divisor = new TextField();
final TextField dividend = new TextField();
Button button = new Button("Click Me");
public Calculation(){
divisor.setCaption("Enter the divisor:");
dividend.setCaption("Enter the dividend:");
button.addClickListener( new Button.ClickListener(){
@Override
public void buttonClick(ClickEvent event) {
System.out.println("this is a test");
}
});
vl.setMargin(true);
vl.setSpacing(true);
vl.addComponents(divisor, dividend, button );
}
}
So my question is, when in the UI class I do
layout.addComponents(title, calculation);
I get an error saying: "The method addComponents(Component...) in the type AbstractComponentContainer is not applicable for the arguments (Label, Calculation)" I've done something similar before, like creating an object of a separate class and add it to the layout and it has worked, this time it doesn't and I'm not sure what it is that I've done wrong...any idea? thanks
Upvotes: 0
Views: 501
Reputation: 4754
The method addComponents(...)
only accepts Component
as arguments.
Your Calculation
class does not extend/implement Component
Upvotes: 1