向表视图Javafx添加图像

向表视图Javafx添加图像,java,image,javafx,tableview,Java,Image,Javafx,Tableview,我想将图像添加到表视图单元格中。我有照片的路径,但不知道如何使图像显示在表中。 表: 图像的路径存储在私有字符串photo中,我希望该图像显示在表中。目前,它只是显示了路径 尝试了注释中的链接,代码如下所示: public void eineMethode() { try { ArrayList<Box> list1 = (ArrayList<Box>)service.listBox(); ImageView imageview = new ImageV

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

图像的路径存储在
私有字符串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();
 }
}
public方法(){
试一试{
ArrayList list1=(ArrayList)service.listBox();
ImageView ImageView=新的ImageView();
imageview.setFitHeight(50);
imageview.setFitWidth(50);
setImage(新图像(“sepm.ss14.e1103974.gui/Pferdebox.jpg”);
tableColumnPhoto.setCellFactory(新回调()
{
@凌驾
公用电话(
表(列arg0){
TableCell单元格=新的TableCell(){
public void updateItem(长方体,布尔空){
如果(框!=null){
VBox vb=新的VBox();
//vb.设置对齐(位置中心);
ImageView ImageView=新图像视图(新图像(“/SEPM2014/src/sepm/ss14/e1103974/gui/Pferdebox.jpg”);
imageview.setFitHeight(50);
imageview.setFitWidth(50);
vb.getChildren().addAll(imageview);
设置图形(vb);
}
}
};
//TODO自动生成的方法存根
返回单元;
}
});
ObservableList l=FXCollections.ObservableList(列表1);
tableViewBox.getItems().setAll(l);
tableColumnBoxNr
.setCellValueFactory(新属性ValueFactory(
"boxNr);;
台柱
.setCellValueFactory(新属性ValueFactory(
"preis");;
桌子
.setCellValueFactory(新属性ValueFactory(
"groesse);;
TableColumninen
.setCellValueFactory(新属性ValueFactory(
"英宁"),;
台柱式芬斯特
.setCellValueFactory(新属性ValueFactory(
“芬斯特”);
桌柱材料
.setCellValueFactory(新属性ValueFactory(
“材料”);
表列爱因斯坦
.setCellValueFactory(新属性ValueFactory(
“爱因斯坦”);
桌柱照片
.setCellValueFactory(新属性ValueFactory(
"照片"),;
tableViewBox.getColumns().setAll(tableColumnBoxNr,
tableColumnPreis,tableColumnGroesse,tableColumnInnen,
tableColumnFenster,tableColumnMaterial,
tableColumnEinstreu,tableColumnPhoto);
//tableViewBox.getItems().setAll(列表1);
}捕获(例外e){
e、 printStackTrace();
}
}
仍然不工作,得到无效的URL错误,而且我不确定如何将图像本身添加到表中,因为在我的实际代码中,我正在将ObservableList“l”添加到表中。
非常感谢您的帮助。提前谢谢。

看看这里@AKS我更改了代码并编辑了我的帖子。仍然无法理解。请参阅此博客:-
private int boxNr;
private float preis;
private int groesse;
private boolean innen;
private boolean fenster;
private String einstreu;
private String material;
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();
 }
}