0

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);
        }
    });
  • Welcome to Stack Overflow! You have posted way to much code in your question, which makes it unclear to us (and to future readers) exactly where the problem is. Please reduce your problem code to 10 lines or less. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and [How to Debug Small Programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – Joe C Sep 30 '17 at 15:53
  • Also, please don't tag multiple languages unless your question is actually about multiple languages. Your question has nothing to do with `c`. – Joe C Sep 30 '17 at 15:53
  • @JoeC Where did i tag C? – Endrit Murseli Sep 30 '17 at 15:57
  • I removed it for you. – Joe C Sep 30 '17 at 15:59
  • i dont see any error "above" – Emanuel Sep 30 '17 at 16:00
  • 1
    `PropertyValueFactory` expects `Property()` methods to return the property, not the value stored inside the property. – fabian Sep 30 '17 at 16:05
  • @EmanuelS I forgot to remove that part of my question. It's not about an error but the reason why i don't see anything changing on the TableView. I apologize. – Endrit Murseli Sep 30 '17 at 16:06
  • @fabian Can you explain your answer further? Maybe with an example? Keep in mind that I'm new to Javafx. Thank you very much. – Endrit Murseli Sep 30 '17 at 16:20
  • read @fabian s comment word for word and compare with your code - all's said that needs to be said ;) – kleopatra Sep 30 '17 at 16:34
  • I am very grateful to you all. It's solved :D – Endrit Murseli Sep 30 '17 at 17:02

0 Answers0