What Im trying to do is copy selected row in one TableView to another one TableView.
public void addMeal()
{
products2 = FXCollections.observableArrayList();
tableProduct.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<productData>() {
@Override
public void changed(ObservableValue<? extends productData> observable, productData oldValue, productData newValue) {
products2.add(new productData(newValue.getName(), newValue.getKcal(), newValue.getProtein(), newValue.getCarb(), newValue.getFat()));
}
});
colProduct2.setCellValueFactory(new PropertyValueFactory<productData, String>("name"));
colKcal2.setCellValueFactory(new PropertyValueFactory<productData, String>("kcal"));
colProtein2.setCellValueFactory(new PropertyValueFactory<productData, String>("protein"));
colCarbs2.setCellValueFactory(new PropertyValueFactory<productData, String>("carb"));
colFat2.setCellValueFactory(new PropertyValueFactory<productData, String>("fat"));
tableProduct2.setItems(products2);
}
products2 is ObservableList, tableProduct2 is TableView, colName2, etc are TableColumns
Problem is that, app is working not correctly. I have to push the button connected with this method first, then after I select row in TableView 1 i get in TableView 2. Whats more, I can click few others rows and they will be added too. Its like this button enables this selection option and what I want is to simply select row, click button, see this row in another TableView. Then I want to select another one, click button again, etc.
Next problem is that, once I click button again, it clears second TableView and from now on, he will add selected items twice, if I click button again, it clears TableView again and now it adds selected item 3 times, etc...