Problem when updating item in a tableview

0

I am working on a code and I would like to know how I can update the elements of a tableview .

That is, I have my code with a editar method that edits the selected components of that table. For example, I have an element that is called prueba and contains a int with value 6. I edit it and call it pruebaedit , change the value of int to 5 and edit that element in ObservableList .

So far so good, but when I give it to save I edit the list but the old data is still shown in the table.

I would like to update the table and every time you edit an element, update the values of this element in the table and show them updated.

    
asked by jose climent penades 16.08.2016 в 10:48
source

1 answer

0

You can try creating a TableView<T> object and pass it as a value to your TableView with data.

For example:

TableView<Producto> table = new TableView<>();
ArrayList<Producto> productos = new ArrayList<>();

//Se agregan elementos a tu TableView
table.getItems().addAll(productos);
table.getColumns().addAll(nombre, clave, tiuni, descrip, exis, precio);

/**
 * Método que actualiza información de TableView
 * @return botón de actualizar
 */
public Button bActualizar() {
    actualizar.setOnAction(new EventHandler<ActionEvent>() { //actualizar es tipo Button
        @Override
        public void handle(ActionEvent event) {
            TableView<Producto> pr = new TableView<>();
            table = pr;  //TableView vacío para que no duplique
            //Llamada al método para mostrar table actualizado
        }
    });
    return actualizar;
}
    
answered by 14.03.2017 в 01:02