【发布时间】:2019-11-26 17:50:27
【问题描述】:
我有一个对话框,其中包含一个复选框和一个文本框。只有在选中复选框时才应启用文本框。
目前我尝试使用以下绑定进行此操作。
CheckBox cbox = new CheckBox("Enable textbox");
TextBox tbox = new TextBox();
tbox.disableProperty().bind(cbox.selectedProperty());
然而,这与我想要的完全相反的效果(当我选择复选框时,文本框会被禁用)。而且我在文本框上找不到“enableProperty”。
我发现文本框有一个“editableProperty()”,并且将它绑定到 selectedProperty 具有我想要的部分预期效果。不过,我觉得禁用仍然是一个更好的选择,因为它在视觉上更直观。
It's probably an easy fix, but how exactly do I have to bind the properties to enable the textbox when the checkbox is selected?
【问题讨论】:
-
在
selected属性上使用BooleanExpression#not()或Bindings#not(ObservableBooleanValue)。例如:...bind(cbox.selectedProperty().not());. -
@Slaw 是的,成功了。非常感谢!
标签: java user-interface javafx