簡體   English   中英

javafx只讀屬性的雙向綁定

[英]javafx bidirectional binding of read only property

當我嘗試編譯此應用程序時,出現有關類型不匹配的錯誤。 這個worker.valueProperty是只讀的,所以我認為這是問題所在。 如何綁定此屬性?

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類

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());
    }
}

您需要一個雙向綁定到rightTableView.itemsProperty的中間屬性。

並將worker.valueProperty偵聽器更改為將worker結果應用於該中間屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM