代码似乎没什么问题,但表没有填充。同一代码在其他地方工作得很好。
public class Test implements Initializable {
@FXML
TableView sort_view;
@FXML
TableColumn sort_id, sort_pname, sort_price, sort_quantity, sort_total;
@Override
public void initialize(URL location, ResourceBundle resources) {
final ObservableList<Sort> data =
FXCollections.observableArrayList();
Sort sort;
SalesDb db = new SalesDb();
ResultSet rs = db.sortProduct();
try {
while (rs.next()) {
int id = rs.getInt("ID");
String productName = rs.getString("ProductName");
String productPrice = rs.getString("ProductPrice");
String quantity = rs.getString("Quantity");
String total = rs.getString("Total");
sort = new Sort(Integer.toString(id),productName,productPrice,quantity,total);
data.add(sort);
System.out.println(sort.getId()+","+sort.getProductName()+","+sort.getPrice()+","+sort.getQuantity()+","+sort.getTotal());
}
}catch(Exception e){
System.out.println("There is an Exception.");
System.out.println(e.getMessage());
}
sort_id.setCellValueFactory(new PropertyValueFactory<Sort, String>("id"));
sort_pname.setCellValueFactory(new PropertyValueFactory<Sort, String>("productName"));
sort_price.setCellValueFactory(new PropertyValueFactory<Sort, String>("price"));
sort_quantity.setCellValueFactory(new PropertyValueFactory<Sort, String>("quantity"));
sort_total.setCellValueFactory(new PropertyValueFactory<Sort, String>("total"));
sort_view.getItems().add(data);
}
}
我的fxml文件如下。
我的桌子不填充,原因可能是什么。
下表如下所示。
请查查有什么问题…