Comment ajouter une Image dans un JavaFx TableView colonne

J'essaie de trouver un moyen d'ajouter une image à un JavaFx TableView colonne de données dans les autres colonnes rempli à partir d'un H2 de la base de données via hibernate. La TableView a été conçu en JavaFx Scene Builder.

C'est ce que j'ai réussi à mettre ensemble pour l'instant:

De La Classe De Contrôleur:

public class HomeController implements Initializable {
@FXML
private TableView<NewBeautifulKiwi> KIWI_TABLE;
@FXML
private TableColumn<NewBeautifulKiwi, Image> KiwiId;
@FXML
private TableColumn<NewBeautifulKiwi, String> Kiwi;
public ObservableList<NewBeautifulKiwi> data;
//Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
KiwiId.setCellFactory(new Callback<TableColumn<NewBeautifulKiwi, Image>, TableCell<NewBeautifulKiwi, Image>>() {
@Override
public TableCell<NewBeautifulKiwi, Image> call(TableColumn<NewBeautifulKiwi, Image> param) {
//Set up the ImageView
final ImageView imageview = new ImageView();
imageview.setFitHeight(50);
imageview.setFitWidth(50);
//Set up the Table
TableCell<NewBeautifulKiwi, Image> cell = new TableCell<NewBeautifulKiwi, Image>() {
public void updateItem(NewBeautifulKiwi item, boolean empty) {
if (item != null) {
imageview.setImage("arrow.png");
}
}
};
//Attach the imageview to the cell
cell.setGraphic(imageview);
return cell;
}
});
Kiwi.setCellValueFactory(new PropertyValueFactory<NewBeautifulKiwi, String>("Kiwi"));
KIWI_TABLE.setItems(gobbledyGook());
}
private ObservableList<NewBeautifulKiwi> gobbledyGook() {
data = FXCollections.observableArrayList();
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
List courses = session.createQuery("from KIWI_TABLE").list();
for (Iterator iterator = courses.iterator(); iterator.hasNext();) {
NewBeautifulKiwi course = (NewBeautifulKiwi) iterator.next();
System.out.println(course.getKiwi());
data.add(course);
}
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
return data;
}
}

J'obtiens une erreur à imageview.setImage("arrow.png"); qui dit Incopatibletypes: String cannot be converted to Image.

C'est ma première fois d'essayer d'ajouter une image dans une TableView.

J'ai regardé autour depuis hier, mais maintenant, je semble être coincé. J'espérais de l'aide. Je voudrais vraiment l'apprécier un peu d'aide.

C'est la classe qui crée la base de données pojo:

@Entity(name = "KIWI_TABLE")
public class NewBeautifulKiwi implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int KiwiId;
private String Kiwi;
public int getKiwiId() {
return KiwiId;
}
public void setKiwiId(int KiwiId) {
this.KiwiId = KiwiId;
}
public String getKiwi() {
return Kiwi;
}
public void setKiwi(String Kiwi) {
this.Kiwi = Kiwi;
}
}

Je vous remercie tous à l'avance.

OriginalL'auteur ILikeProgramming | 2014-02-25