我想将一个图像添加到表视图单元格中 . 我有照片的路径,但不知道如何使图像显示在表格中 . 表:

ArrayList<Box> list1 = (ArrayList<Box>)service.listBox();

 ObservableList<Box> l = FXCollections.observableList(list1);

 tableViewBox.getItems().setAll(l);

 tableColumnBoxNr
   .setCellValueFactory(new PropertyValueFactory<Box, Integer>(
  "boxNr"));
  tableColumnPreis
    .setCellValueFactory(new PropertyValueFactory<Box, Float>(
  "preis"));
  tableColumnGroesse
    .setCellValueFactory(new PropertyValueFactory<Box, Integer>(
  "groesse"));
  tableColumnInnen
    .setCellValueFactory(new PropertyValueFactory<Box, Boolean>(
  "innen"));
  tableColumnFenster
.setCellValueFactory(new PropertyValueFactory<Box, Boolean>(
  "fenster"));
  tableColumnMaterial
.setCellValueFactory(new PropertyValueFactory<Box, String>(
  "material"));
  tableColumnEinstreu
    .setCellValueFactory(new PropertyValueFactory<Box, String>(
  "einstreu"));
  tableColumnPhoto
.setCellValueFactory(new PropertyValueFactory<Box, String>(
  "photo"));

以下是“Box”的样子:

private int boxNr;
private float preis;
private int groesse;
private boolean innen;
private boolean fenster;
private String einstreu;
private String material;
private String photo;

图像的路径存储在 private String photo 中,我希望该图像显示在表格中 . 目前它只是显示路径 .

尝试了评论中的链接,代码如下所示:

public void eineMethode() {
 try {

   ArrayList<Box> list1 = (ArrayList<Box>)service.listBox();

   ImageView imageview = new ImageView();


     imageview.setFitHeight(50);
     imageview.setFitWidth(50);
     imageview.setImage(new Image("sepm.ss14.e1103974.gui/Pferdebox.jpg"));


     tableColumnPhoto.setCellFactory(new Callback<TableColumn<Box,ImageView>,TableCell<Box,ImageView>>()
       {

 @Override
 public TableCell<Box, ImageView> call(
   TableColumn<Box, ImageView> arg0) {
  TableCell<Box,ImageView> cell = new TableCell<Box,ImageView>(){

   public void updateItem(Box box, boolean empty) {
    if(box!=null) {
     VBox vb=new VBox();
     //vb.setAlignment(Pos.CENTER);
      ImageView imageview = new ImageView(new Image("/SEPM2014/src/sepm/ss14/e1103974/gui/Pferdebox.jpg"));


            imageview.setFitHeight(50);
            imageview.setFitWidth(50);
            vb.getChildren().addAll(imageview);
            setGraphic(vb);
    }
   }
  };
  // TODO Auto-generated method stub
  return cell;
 }

       });


   ObservableList<Box> l = FXCollections.observableList(list1);

   tableViewBox.getItems().setAll(l);

  tableColumnBoxNr
.setCellValueFactory(new PropertyValueFactory<Box, Integer>(
  "boxNr"));
  tableColumnPreis
.setCellValueFactory(new PropertyValueFactory<Box, Float>(
  "preis"));
  tableColumnGroesse
.setCellValueFactory(new PropertyValueFactory<Box, Integer>(
  "groesse"));
  tableColumnInnen
.setCellValueFactory(new PropertyValueFactory<Box, Boolean>(
  "innen"));
  tableColumnFenster
.setCellValueFactory(new PropertyValueFactory<Box, Boolean>(
  "fenster"));
  tableColumnMaterial
.setCellValueFactory(new PropertyValueFactory<Box, String>(
  "material"));
  tableColumnEinstreu
.setCellValueFactory(new PropertyValueFactory<Box, String>(
  "einstreu"));
  tableColumnPhoto
.setCellValueFactory(new PropertyValueFactory<Box, ImageView>(
  "photo"));
  tableViewBox.getColumns().setAll(tableColumnBoxNr,
   tableColumnPreis, tableColumnGroesse, tableColumnInnen,
tableColumnFenster, tableColumnMaterial,
tableColumnEinstreu, tableColumnPhoto);

  //tableViewBox.getItems().setAll(list1);
 } catch (Exception e) {
  e.printStackTrace();
 }
}

仍然没有工作,并获得无效的URL错误,而且我不确定如何将Image本身添加到表中,就像在我的实际代码中我将ObservableList“l”添加到表中 . 非常感谢帮助 . 提前致谢 .