我在JavaFX中使用TableView
但是tableview没有显示任何数据,这是我的代码。
public static class person {
private final SimpleIntegerProperty SR;
private final SimpleStringProperty URL;private person(int sr1,String url1 ){
this.SR=new SimpleIntegerProperty(sr1);
this.URL=new SimpleStringProperty(url1);
}
public int getsr() {
return SR.get();
}
public void setsr(int sr1) {
this.SR.set(sr1);
}
public String geturl() {
return URL.get();
}
public void seturl(String url2) {
this.URL.set(url2);
}
}
public TableView<person> table; TableColumn firstNameCol = new TableColumn("First Name");
TableColumn lastNameCol = new TableColumn("Last Name");
private final ObservableList<person> data1 =
FXCollections.observableArrayList(
new person((int)1, "Smith"),
new person((int)2, "Johnson"),
new person((int)3, "Williams"),
new person((int)4, "Jones"),
new person((int)5, "Brown")
);
public void btnScrapping(ActionEvent event) {
table.setEditable(true);
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(new PropertyValueFactory<person,Integer>("SR"));
lastNameCol.setMinWidth(500);
lastNameCol.setCellValueFactory(new PropertyValueFactory<person,String>("URL"));
table.setItems(data1);
table.getColumns().addAll(firstNameCol, lastNameCol);
}