我在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项目中进行这些更改?