有没有办法将javafx按钮绑定到File属性;如果文件存在或不启用/禁用按钮

时间:2015-08-21 14:03:53

标签: javafx javabeans

我有没有办法绑定选定的文件,如果它退出或没有启用或禁用javaFX按钮? 我只看到字符串等的bean属性,而不是文件。 我需要根据文件值是否为有效文件来启用或禁用按钮。

非常感谢

1 个答案:

答案 0 :(得分:3)

ObjectProperty<File> file = new SimpleObjectProperty<>();
BooleanBinding fileExists = Bindings.createBooleanBinding(() -> 
    file.get() != null && file.get().exists(),
    file);

Button button = new Button("OK");
button.disableProperty().bind(fileExists.not());