code: private void setupCheckboxEventHandlers() {
      for (int i = 0; i < checkboxes.size(); i++) {
        final int j = i;
  
        checkboxes.get(i).setOnAction(event -> {
          if (checkboxes.get(j).isSelected()) {
            field.select(j);
          } else {
            field.deselect(j);
          }
        });
      }
    }
docs: Sets up event handlers for all checkboxes.