dimanche 7 janvier 2018

How to bind checkbox to variable in JavaFX?

I have controller class like this

public class Controller{
  private final Model model;

  @FXML
  private CheckBox 1;
  @FXML
  private CheckBox 2;
  @FXML
  private CheckBox 3;

  public Controller(Model model) {
       this.model = model;
   }

  @FXML
  private void initialize(){
     1.selectedProperty().bind(model.initProperty());
  }
}

My model class look like this

public class Model{
   private final BooleanProperty init = new SimpleBooleanProperty(false);

   public BooleanProperty initProperty() {
      return init;
   }

   public final Boolean getInit() {
      return initProperty().get();
   }

   public final void setInit(Boolean init) {
      initProperty().set(init);
   }
}

I want to bind CheckBox to variable in Model. I am currently doing this, but I am getting CheckBox.selected : A bound value cannot be set. Error.

The second thing I wanna do is to check, which checkbox was selected or disselected and according to this set boolean variable in model. Is there some way how to do this ?




Aucun commentaire:

Enregistrer un commentaire