Search code examples
javafxfxmlproperty-binding

binding more than two property in fxml


Suppose I want to bind disable property of a button with a checkbox's selected property. I know this method to bind them in FXML:

<Button disable="${firstcheckbox.selected}"/>

But what if I have two checkboxes and I want to bind the button's disable property with both the checkbox's selected property. Yes, I know I can do that in my java controller but I was just wondering if there is a way to do that in FXML.

If it's not clear what did I want, this is the Java code alternative to what I actually wanted:

mybutton.disableProperty().bind(firstcheckbox.selectedProperty().and(secondcheckbox.selectedProperty()));

Now I want to do this in FXML instead.


Solution

  • According to the documentation, you can use the operator && in expression binding.

    Since the & character has special meaning in XML, you need to properly escape it: one way is to use &amp; to represent a single & character.

    <Button disable="${firstcheckbox.selected &amp;&amp; secondcheckbox.selected}"/>