【问题标题】:Bidirectional bind between a boolean property and two RadioButtons布尔属性和两个 RadioButtons 之间的双向绑定
【发布时间】:2017-07-09 17:57:28
【问题描述】:

我有一个类 Person,它有一个名为“流派”的布尔属性,其值将 对男孩来说是真的,对女孩来说是假的。

我需要在 Person.genre 和两个 RadioButtons 之间创建一个双向绑定 这样当我的 person 对象填充了来自数据源的数据时 RadioButtons 将被相应地设置(如果 Person.genre 为真,如果Person.genre 为假,女性 RadioButton 检查)或用户是否点击 如果用户单击女性,男性 RadioButton Person.genre 将设置为 true RadioButton Person.genre 将被设置为 false。

请帮助我获得最合适的做法:应该 我使用Bindings APIRadioButton.bindBidirectional 方法与 Person.genreProperty() 或相反,甚至使用更改监听器???

最好的问候, 罗莫尔多。

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    简单:

    person.genreProperty().bindBidirectional(male.selectedProperty());
    

    另一个单选按钮将与ToggleGroup同步。

    【讨论】:

      猜你喜欢
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      相关资源
      最近更新 更多