Search code examples
javafxjavafx-2javafx-8fxml

How to get Editable Tableview Cell value after edit complete in JavaFX FXML


I have a TableView selectedProductsTable with editable column quantityColumn. I want to take value after user edit column. method gets called without problem but I don't how to get the value.

@FXML
private TableView selectedProductsTable;
@FXML
private TableColumn quantityColumn;
.......

@Override
public void initialize(URL url, ResourceBundle rb) {
   selectedProductDataList = FXCollections.observableArrayList();
   quantityColumn.setCellFactory(TextFieldTableCell.forTableColumn());
}

@FXML
public void onEditCommitSelectedProductTable( ){

    // this method fires when user press enter after finish editing "Quantity" column value.

    // how to get Edited value


}

I'm adding values to the table in method which get called in button click. image of GUI


Solution

  • The onEditCommit handler takes a CellEditEvent object as its parameter, which contains information about the event, including the new value. So you can do

    @FXML
    public void onEditCommitSelectedProductTable(CellEditEvent<?,?> event){
        Object newValue = event.getNewValue();
        // other data that might be helpful:
        TablePosition<?,?> position = event.getTablePosition();
        int row = position.getRow();
        // etc ...
    }