【问题标题】:add image from ObservableList to tableview将图像从 ObservableList 添加到 tableview
【发布时间】:2016-04-04 21:01:51
【问题描述】:

我在 Animal 类中有一个字符串变量“image”。

然后我将其添加到 ObservableList 中,然后将其添加到 TableView。

我下面的代码是显示图像的位置,但我希望它显示实际图像

最好的方法是什么。谢谢!

TableColumn<Animal, String> imgCol = new TableColumn<>("IMAGE");
imgCol.setPrefWidth(200);
imgCol.setCellValueFactory(new PropertyValueFactory<>("_image"));

【问题讨论】:

    标签: image tableview observablelist


    【解决方案1】:
    Managed to get it working.
    
    imgCol.setCellFactory(col -> new TableCell<Animal, String>() {
                    ImageView imageview = new ImageView();
                    @Override
                    public void updateItem(String valid, boolean empty) {
                        super.updateItem(valid, empty);
                        if (valid != null) {
                            imageview.setImage(new Image(valid));
                            imageview.setFitWidth(90);
                            imageview.setFitHeight(90);
                            imageview.setPreserveRatio(true);
                            imageview.setSmooth(true);
                            setGraphic(imageview);
                        }else{
    
                            setGraphic(null);
                        }
                    }
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      相关资源
      最近更新 更多