我有没有办法绑定选定的文件,如果它退出或没有启用或禁用javaFX按钮? 我只看到字符串等的bean属性,而不是文件。 我需要根据文件值是否为有效文件来启用或禁用按钮。
非常感谢
答案 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());