let's consider this We have an article and an article may be stored in many magasins(Stores) and vice versa we can store many articles in one Store.
lets say we have
class Article{
int id_article;
String name;
List<Magasin> magasins;
List<Magasin> getMagasins{
return magasins;
}
lets say that Magasin class look like this
class Magasin{
int id_magasin;
String name;
//getters and setters
}
And let's say I have My tableView in javafx : TableView tblArticles;
first column contain article name and second column Want it to contain name of all magasins (stores ) that the articles is stored in ( magasin-1, magasin-2 .. magasin-N)
I want also to ask if I can make the cell as a column that means that every name of song will be display vertically just like a list view and all of them for sure for one specif artist ..
UPDATE : this is the code I have added to my controller :
//FRom FXML file
@FXML
TableColumn<Article, List<Magasin>> colMag ;
PropertyValueFactory<Article, List<Magasin>> mag = new PropertyValueFactory<>("magasins");
//CellValueFactory
colMag.setCellValueFactory(mag);
//cell Factory
colMag2.setCellFactory( col -> {
ListView<Magasin> listView = new ListView<>();
listView.setCellFactory(lv -> new ListCell<Magasin>() {
@Override
public void updateItem(Magasin magasin, boolean empty) {
super.updateItem(magasin, empty);
if (empty) {
setText(null);
} else {
setText(magasin.getLibelle());
}
}
});
return new TableCell<Article, List<Magasin>>() {
@Override
public void updateItem(List<Magasin> mags, boolean empty) {
super.updateItem(mags, empty);
if (empty) {
setGraphic(null);
} else {
listView.getItems().setAll(mags);
setGraphic(listView);
}
}
};
});
When I run this I got the error :
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at java.util.AbstractCollection.addAll(AbstractCollection.java:343)
at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:99)
at javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:88)
at controllers.DashboardController$6.updateItem(DashboardController.java:1180)
at controllers.DashboardController$6.updateItem(DashboardController.java:1173)
at javafx.scene.control.TableCell.updateItem(TableCell.java:663)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:468)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:116)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:533)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.init(TableRowSkinBase.java:147)
at com.sun.javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:64)
at javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:212)
at javafx.scene.control.Control.impl_processCSS(Control.java:872)