Javafx 8使用TableView和Service加载大数据项bug

时间:2014-07-16 13:38:38

标签: java javafx tableview javafx-8

我在win7上使用64位jdk8。 但是在加载大数据并将其与tabview.itemsProperty().bind(service.valueProperty())

绑定时,我发现了一个明显的错误

当我在TableView上向下拖动垂直滚动条后执行service.restart时,TableView项目不会改变。

这是我的代码:

1)的任务

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
public class TestTask extends Task<ObservableList<Person>> {
    @Override
    protected ObservableList<Person> call() throws Exception {
        ObservableList<Person> data = FXCollections.observableArrayList();
        for (int i = 0; i < 100000; i++) {
            data.add(new Person("Jacob" + i, "Smith" + i, "jacob.smith@example.com"));
        }
        return data;
    }
}

2)人

import javafx.beans.property.SimpleStringProperty;
public class Person {
    private final SimpleStringProperty firstName;
    private final SimpleStringProperty lastName;
    private final SimpleStringProperty email;
    Person(String fName, String lName, String email) {
        this.firstName = new SimpleStringProperty(fName);
        this.lastName = new SimpleStringProperty(lName);
        this.email = new SimpleStringProperty(email);
    }
    public String getFirstName() {
        return firstName.get();
    }
    public void setFirstName(String fName) {
        firstName.set(fName);
    }
    public String getLastName() {
        return lastName.get();
    }
    public void setLastName(String fName) {
        lastName.set(fName);
    }
    public String getEmail() {
        return email.get();
    }
    public void setEmail(String fName) {
        email.set(fName);
    }
}

3)控制器

    public class FXMLDocumentController implements Initializable {
    @FXML
    private TableView<Person> tv_table;
    @FXML
    private TableColumn tc_firstName;
    @FXML
    private TableColumn tc_lastName;
    @FXML
    private TableColumn tc_email;
    TestServer ts = new TestServer();
    ObservableList<Person> data = FXCollections.observableArrayList();
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        tc_firstName.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
        tc_lastName.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
        tc_email.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));
        tv_table.itemsProperty().bind(ts.valueProperty());
    }
    @FXML
    public void test() {
        data.clear();
        for (int i = 0; i < 1000000; i++) {
            data.add(new Person("Jacob" + i, "Smith" + i, "jacob.smith@example.com"));
        }
    }
}

如何在TableView项目中进行这些更改?

0 个答案:

没有答案