I have two different types (byte to Model and imageView to View) so I had to use two classes "ProductTableColumnModel" (help class for the picture column ) & Model "Product"
pictureColumn.setCellValueFactory(new PropertyValueFactory<ProductTableColumnModel, ImageView>("picture"));
but other columns like this:
descColumn.setCellValueFactory(new PropertyValueFactory<Product, String>("description"));
Product class:
public class Product {
private byte[] picture;
@Column(name= "picture")
public byte[] getPicture() {
return this.picture;
}
public void setPicture(byte[] picture) {
this.picture = picture;
}
}
ProductTableColumnModel class:
public class ProductTableColumnModel {
private ImageView picture;
public ImageView getPicture() {
return this.picture;
}
public void setPicture(ImageView picture) {
this.picture = picture;
}
in ProductViewController class:
@FXML
TableView <Product> table_Products;
@FXML
TableColumn <Product, String> productName;
@FXML
TableColumn <Product, String> descColumn;
@FXML
TableColumn <ProductTableColumnModel, ImageView> pictureColumn;
.....
// show data in TableView
for(Product p : getProducts() ) {
Product product = new Product();
product.setProductName(String.valueOf(p.getProductName() ));
product.setDescription(String.valueOf(p.getDescription()));
byte[] pictureImageInByte = p.getPicture();
if(pictureImageInByte != null) {
ByteArrayInputStream imageDate = new ByteArrayInputStream(pictureImageInByte);
Image image = new Image(imageDate);
/* ???????
*/
}
tableData.addAll(product);
}
/* set table items */
table_Products.setItems(tableData);
private void intializeTableColumns() {
tableData = FXCollections.observableArrayList();
productName.setCellValueFactory(new PropertyValueFactory<Product, String>("productName"));
descColumn.setCellValueFactory(new PropertyValueFactory<Product, String>("description"));
pictureColumn.setCellValueFactory(new PropertyValueFactory<ProductTableColumnModel, ImageView>("picture"));
}
Can anyone help me to write the correct code after this?
if(pictureImageInByte != null) {
ByteArrayInputStream imageDate = new ByteArrayInputStream(pictureImageInByte);
Image image = new Image(imageDate);
/* ???????
*/
}