【问题标题】:Enable a textbox when a checkbox is selected选中复选框时启用文本框
【发布时间】: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?

【问题讨论】:

标签: java user-interface javafx


【解决方案1】:
tbox.disableProperty().bind(cbox.selectedProperty());

That means when the cbox is selected the tbox will disable.您可以使用 not 属性:

tbox.disableProperty().bind(cbox.selectedProperty().not());

【讨论】:

    猜你喜欢
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多