【问题标题】:Binding a button to multiple boolean values javafx将按钮绑定到多个布尔值 javafx
【发布时间】:2018-01-29 15:46:42
【问题描述】:

我有 5 个文本字段,它们都有我为它们创建的验证器。当该字段已被验证且正确时,我调用一个将组设置为可见的方法:

public void fadeInLabel(Group groupName){
    groupName.setOpacity(0);
    groupName.setVisible(true);
    FadeTransition ft = new FadeTransition(Duration.millis(300), groupName);
    ft.setInterpolator(Interpolator.EASE_OUT);
    ft.setFromValue(0);
    ft.setToValue(1);
    ft.play();
} 

我想在与这些文本字段的验证器关联的所有组都可见时启用一个按钮。

我尝试使用 BooleanBinding,但它不允许我绑定布尔值 - 我必须绑定布尔属性。

编辑: 以下是我尝试但返回错误“布尔值无法取消引用”的代码

BooleanBinding accountBind = completeLabel0.isVisible().or(completeLabel1.isVisible());
createButton.disableProperty().bind(accountBind);

【问题讨论】:

  • “我尝试过使用 BooleanBinding,但它不允许我绑定布尔值 - 我必须绑定布尔属性。” 这不是真的。 bind 方法接受任何 ObservableValue<Boolean>。发布相关代码(即您尝试绑定按钮的disableProperty()。)
  • 不完全确定您的代码是什么样的,但布尔属性可以独立发生,并且可以通过更改侦听器触发任何代码。
  • @James_D 我已经编辑了帖子,代码在上面^^

标签: java user-interface button javafx


【解决方案1】:
BooleanBinding accountBind = completeLabel0.isVisible().or(completeLabel1.isVisible());
createButton.disableProperty().bind(accountBind);

应该是

BooleanBinding accountBind = completeLabel0.visibleProperty().or(completeLabel1.visibleProperty());
createButton.disableProperty().bind(accountBind);

假设completeLabel0completeLabel1 是某种节点。

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 2023-03-18
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    相关资源
    最近更新 更多