代码似乎没有什么问题,但表没有填充。同一代码在其他地方运行良好。
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文件如下。
我的table没有人,可能是什么原因。下表所示。。
请调查一下有什么问题。。。
1条答案
按热度按时间3npbholx1#
这只是因为没有正确使用命名约定,因为有多个项目,我不得不使用data.addall(sort)而不是data.add(sort)。