Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add checkbox into FormLayout (Vaadin)

I am trying to add the checkbox into the FormLayout, but it throwing an warning:

My code

private void createEditorLayout(SplitLayout splitLayout) {

    Div editorLayoutDiv = new Div();
    editorLayoutDiv.setClassName("editor-layout");

    Div editorDiv = new Div();
    editorDiv.setClassName("editor");
    editorLayoutDiv.add(editorDiv);

    FormLayout formLayout = new FormLayout();
    monthAndYear = new DatePicker("Month and year");
    organizationId = new TextField("Organiziation ID");
    userId = new TextField("User ID");
    onlyForOrganization = new Checkbox("Only for organization");

    Component[] fields = new Component[]{monthAndYear, onlyForOrganization, organizationId, userId}; 

    formLayout.add(fields);
    editorDiv.add(formLayout);
    createButtonLayout(editorLayoutDiv);
    splitLayout.addToSecondary(editorLayoutDiv);

}

The problematic is this row:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Component[] fields = new Component[]{monthAndYear, onlyForOrganization, organizationId, userId}; 

It showing warning:

Required type: Component
Provided: Checkbox

Is it possible to somehow add a checkbox to the FormLayout?

>Solution :

Sounds like you are importing the wrong Checkbox. Make sure the import is com.vaadin.flow.component.checkbox.Checkbox.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading