2016-04-04 17 views
0

私は、AnimalクラスにString変数 "image"を持っています。ObservableListからtableviewに画像を追加する

これをObservableListに追加して、それをTableViewに追加します。以下

私のコードでは、画像の位置を表示しているが、私はそれが実際の画像これを行うための最善の方法は何

を表示したいです。ありがとう!

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

答えて

0
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); 
        } 
       } 
      });