4

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.

4

1 回答 1

3

根据文档,您可以&&在表达式绑定中使用运算符。

由于&字符在 XML 中具有特殊含义,因此您需要对其进行适当的转义:一种方法是使用&amp;来表示单个&字符。

<Button disable="${firstcheckbox.selected &amp;&amp; secondcheckbox.selected}"/>
于 2017-12-12T11:47:04.217 回答