将TableView itemsProperty()绑定到Service valueProperty()

时间:2013-06-07 09:50:02

标签: java javafx-2

如何将TableView项绑定到正在运行的服务值,例如ListView

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

当我尝试时遇到编译时错误:

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

修改:我的服务类

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

1 个答案:

答案 0 :(得分:2)

您是如何定义服务的?

尝试类似:

public class MyService extends Service<ObservableList<TodoTAsk>>