SOLVED:
PropertyValueFactory expects Property() methods to return the property, not the value stored inside the property
MY QUESTION WAS:
I am making an applications which makes use of a TableView
. The TableView
updates every time an item in a ListView
is selected. The problem is every time I click on an item in the ListView
, nothing happens in the TableView
.
Short code about the TableView:
private TableView<Gebruik> tableView;
tableView = new TableView<>();
TableColumn<Gebruik, String> clmDatum = new TableColumn<Gebruik, String>("Datum");
TableColumn<Gebruik, String> clmBoek = new TableColumn<Gebruik, String>("Boek");
TableColumn<Gebruik, String> clmFouten = new TableColumn<Gebruik, String>("Aantal fouten");
TableColumn<Gebruik, String> clmJuisten = new TableColumn<Gebruik, String>("Aantal juist");
clmDatum.setCellValueFactory(new PropertyValueFactory<Gebruik,String>("datum"));
clmBoek.setCellValueFactory(new PropertyValueFactory<Gebruik,String>("boek"));
clmFouten.setCellValueFactory(new PropertyValueFactory<Gebruik,String>("fouten"));
clmJuisten.setCellValueFactory(new PropertyValueFactory<Gebruik,String>("juisten"));
tableView.getColumns().addAll(clmDatum,clmBoek,clmFouten,clmJuisten);
Gebruik class: This class has some properties which i think match with the Columns in the TableView?
package Views.Menu.Profiel;
import javafx.beans.property.SimpleStringProperty;
public class Gebruik {
private final SimpleStringProperty datum;
private final SimpleStringProperty boek;
private final SimpleStringProperty fouten;
private final SimpleStringProperty juisten;
Gebruik(String datum, String juisten, String fouten, String boek) {
this.datum = new SimpleStringProperty(datum);
this.boek = new SimpleStringProperty(boek);
this.fouten = new SimpleStringProperty(fouten);
this.juisten = new SimpleStringProperty(juisten);
}
public String datumProperty() {
return datum.get();
}
public String boekProperty() {
return boek.get();
}
public String foutenProperty() {
return fouten.get();
}
public String juistenProperty() {
return juisten.get();
}
public void setDatum(String datum) {
this.datum.set(datum);
}
public void setBoek(String boek) {
this.boek.set(boek);
}
public void setFouten(String fouten) {
this.fouten.set(fouten);
}
public void setJuisten(String juisten) {
this.juisten.set(juisten);
}
}
My ChangeListener:
There are text-files which I want to read every time an item of the ListView
is selected. After I read the file (corresponding with the item in the ListView) I split the data in a way that it is possible for me to make Gebruik objects. These objects will be put in the observableArrayList() obsGebruik
.
view.getListView().getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
ObservableList<Gebruik> obsGebruik = FXCollections.observableArrayList();
String dir = System.getProperty("user.home");
Path path = Paths.get(dir + "/Al Arabia.jar/AppData/Save/dataSave/" + newValue + ".txt");
try {
List<String> lines = new ArrayList<>();
lines = Files.readAllLines(path, Charset.defaultCharset());
String[] gegevens = lines.toString().replace("]","").replace("[","").replace(",","").split("---");
for (String s : gegevens){
String[] gegevens2 = s.split("\t");
obsGebruik.add(new Gebruik(gegevens2[0],gegevens2[1],gegevens2[2],gegevens2[3]));
}
} catch (IOException e) {
e.printStackTrace();
}
view.getTableView().setItems(obsGebruik);
}
});