Salah Eddine Taouririt
Salah Eddine Taouririt

Reputation: 26415

Bind a TableView itemsProperty() to Service valueProperty()

How can I bind a TableView items to a running service value like in a ListView:

todoList.itemsProperty().bind(service.valueProperty());

When I tried I get a compile-time error:

error: method bind in interface Property<T> cannot be applied to given types:
required : ObservableValue<? extends ObservableList<TodoTAsk>>
found : ReadOnlyObjectProperty<List<TodoTask>>  

Edit: My service class

public final class AllTasks extends Service<ObservableList<TodoTask>> {
    @Override
    protected Task<ObservableList<TodoTask>> createTask() {
       return new Task<ObservableList<TodoTask>>() {
          @Override
          protected ObservableList<TodoTask> call() throws Exception {
          ObservableList<TodoTask> list =      FXCollections.observableArrayList();             
         //    list.addAll(new TaskRepository().getAllTasks());
          for (TodoTask task : new TaskRepository().getAllTasks()) {
              Thread.sleep(1500);
          list.add(task);
          }
          System.out.println(list);
          return list;
        }
     }; 
   }
}

Upvotes: 1

Views: 695

Answers (1)

Puce
Puce

Reputation: 38132

How did you define your Service?

Try something like:

public class MyService extends Service<ObservableList<TodoTAsk>>

Upvotes: 2

Related Questions