In TableView I use ObservableList<Product> productList . To change the necessary data, use an object from the collection, but after saving nothing changes until the item is added and deleted. How to deal with it?

I get the object like this:

  table.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { if (newSelection != null) { selectedProd=(Product)table.getSelectionModel().getSelectedItem(); //метод(),в котором отпрвляю объект и редактирую его } }); 
  • How do you change the data? What specific object for the list are using? - Mikhail Vaysman
  • @MikhailVaysman added - Vladislav Solopov
  • Update your question instead of posting comments - Mikhail Vaysman
  • @ MikhailVaysman + - Vladislav Solopov
  • one
    table.refresh (); - Mikhail Ketov

1 answer 1

If you use data of type Property, the update problem should be solved for an example:

 class Product{ StringProperty testName ; public Product(String testName ){ this.testName = new SimpleStringProperty(testName); } public StringProperty getTestName() { return testName; } public void setTestName(StringProperty testName) { this.testName = testName; } } 

And already in the controller

 nameColumn.setCellValueFactory(cellData -> cellData.getValue().getTestName()); 

If I remember correctly when editing testName, the table will automatically be updated. And then you can do without table.refresh ();