[英]javafx bidirectional binding of read only property
When I try to compile this application I get error about types not matching. 当我尝试编译此应用程序时,出现有关类型不匹配的错误。 This worker.valueProperty is read-only, so I think that this is the problem.
这个worker.valueProperty是只读的,所以我认为这是问题所在。 How to bind this property?
如何绑定此属性?
public void bindToWorker(final Worker<ObservableList<FileForTableView>> worker)
{
// Bind Labels to the properties of the worker
rightTableView.itemsProperty().bindBidirectional(worker.valueProperty());
}
CopyFileTask task = new CopyFileTask(source, destination);
bindToWorker(task);
CopyFileTask class CopyFileTask类
public class CopyFileTask extends Task<ObservableList<FileForTableView>> {
private File source;
private File destination;
//constructors here
// The task implementation
@Override
protected ObservableList<FileForTableView> call()
{
final ObservableList<FileForTableView> results = Controller.getDirectoryContent(destination);
// Update the title
this.updateTitle("Prime Number Finder Task");
try {
copyFile(source, destination);
System.out.println("file copied");
results.add(new FileForTableView(destination.getName(), destination.length(), destination.isDirectory()));
} catch (IOException e) {
e.printStackTrace();
}
return results;
}
private static void copyFile(File source, File destination) throws IOException {
Files.copy(source.toPath(), destination.toPath());
}
}
You need an intermediate property binded bidirectionally to your rightTableView.itemsProperty
. 您需要一个双向绑定到
rightTableView.itemsProperty
的中间属性。
And change listener for worker.valueProperty
where you apply worker result to that intermediate property. 并将
worker.valueProperty
侦听器更改为将worker结果应用于该中间属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.