【问题标题】:binding more than two property in fxml在 fxml 中绑定两个以上的属性
【发布时间】:2018-05-25 22:15:37
【问题描述】:

假设我想将按钮的禁用属性与复选框的选定属性绑定。我知道这种方法可以将它们绑定在FXML

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

但是如果我有两个复选框并且我想将按钮的禁用属性与复选框的选定属性绑定怎么办。是的,我知道我可以在我的 java 控制器中做到这一点,但我只是想知道在 FXML 中是否有办法做到这一点。

如果不清楚我想要什么,这是我真正想要的 Java 代码替代方案:

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

现在我想在 FXML 中执行此操作。

【问题讨论】:

    标签: javafx fxml property-binding


    【解决方案1】:

    根据documentation,可以在表达式绑定中使用&amp;&amp;操作符。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 2011-12-03
      • 2014-06-07
      • 1970-01-01
      相关资源
      最近更新 更多