javafx A bound value cannot be set.

0

Ta linkia kodu:

rightTableView.setItems(getDirectoryContent(new File(rightPathLabel.getText())));

wywołuje wyjatek A bound value cannot be set.

Tutaj jest ten bind:

public void bindToWorker(final Worker<ObservableList<FilesForTableView>> worker)
    {
        // Bind Labels to the properties of the worker
        rightTableView.itemsProperty().bind(worker.valueProperty());

    }

z tego co sie dowiedziałem to chyba ten bind musi być bidirectional tylko nie wiem jak to ustawić

0

Problem chyba jest w tym, ze jeśli zmienić linie na taką:

rightTableView.itemsProperty().bindBidirectional(worker.valueProperty());

to valueProperty jest read only. Jak to teraz zmienić?
Klasa wygląda tak:

package sample;

import javafx.collections.ObservableList;
import javafx.concurrent.Task;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class CopyFileTask extends Task<ObservableList<FilesForTableView>> {

    private File source;
    private File destination;

    public CopyFileTask(File source, File destination) {
        this.source = source;
        this.destination = destination;
    }

    public CopyFileTask(String sourceString, String destinationString) {
        this.source = new File(sourceString);
        this.destination = new File(destinationString);
    }

    // The task implementation
    @Override
    protected ObservableList<FilesForTableView> call()
    {
        final ObservableList<FilesForTableView> results = Controller.getDirectoryContent(destination);
        // Update the title
        this.updateTitle("Prime Number Finder Task");

        // Sleep for some time
        try {
            copyFile(source, destination);
            System.out.println("file copied");
            results.add(new FilesForTableView(destination.getName(), destination.length(), destination.isDirectory()));
        } /*catch (InterruptedException e) {
                // Check if the task is cancelled
                if (this.isCancelled())
                {
                    break;
                }
            }*/ catch (IOException e) {
                e.printStackTrace();
        }
        return results;
    }

    @Override
    protected void cancelled()
    {
        super.cancelled();
        updateMessage("The task was cancelled.");
    }

    @Override
    protected void failed()
    {
        super.failed();
        updateMessage("The task failed.");
    }

    @Override
    public void succeeded()
    {
        super.succeeded();
        updateMessage("The task finished successfully.");
    }


    private static void copyFile(File source, File destination) throws IOException {
        Files.copy(source.toPath(), destination.toPath());
    }
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1