Time for action – creating a custom component
Have you ever accepted license terms when installing software? Sometimes you can click the Install button only and only if you have previously checked a Yeah right. I do Accept the Terms checkbox. Let's make a custom component to emulate that corporate praised behavior. The steps to create a custom component are as follows:
Create a new Vaadin project with the name customcomponent using your IDE.
Create a new class extending
CustomComponent
:public class AcceptTermsButton extends CustomComponent { }
We need three components: a
CheckBox
, aButton
, and aVerticalLayout
:public class AcceptTermsButton extends CustomComponent { private VerticalLayout layout = new VerticalLayout(); private CheckBox checkbox = new CheckBox(); private Button button = new Button(); }
Note
We are defining the components as class members only to emphasize that we are creating a composition of objects, but actually we only need
button
to be a class member.Create a constructor...