Javafx 8: Updating the Tableview after closing the window

Asked

Viewed 474 times

0

I have a rating registration screen and a rating management screen from a library system. After registering a new rating, I would like the Tableview ratings, on the management screen, to be updated showing the new record. I repeat the query in the bank and pass the values of the new query to the list, but it does not update on the screen. Here I call the method to redo the query after saving the information in the bank:

{Rotina que salva a informação no banco}
GerenciarClassificacoesController controller = new GerenciarClassificacoesController(); 
controller.atualizarTableView();

This is where he redoes the query and arrow the items in Tableview:

public class GerenciarClassificacoesController(){
    @FXML
    private void TableView<ClassificacaoLivro> tableClassificacoes;
    ...
    public void atualizarTableView(){
         itens = FXCollections.observableArrayList(servico.getClassificacoes());
         tableClassificacoes.setItems(itens);
         tableClassificacoes.refresh();
    }
}

It falls into the method updateTableView, it redoes the database query and brings the right information, but it does not arrow in Tableview. Please help me :p NOTE: This same method (updateTableView) is called in the screen initialize, and works correctly, when I call out (another file) it doesn’t work.

1 answer

1

Hello, you are creating a new instance of Managementlassificacoescontroller, so nothing is updated. You must pass the current instance of it to the registration controller and call the update methodTableView() from that instance. Example:

CadastroClassificacoesController cadastro controller = fxmlloader.getController();
cadastro.setGerenciadorController(this); // caso esteja chamando a partir dele mesmo
...

In Registerscontroller change your registration method to:

{Rotina que salva a informação no banco}
gerenciadorController.atualizarTableView();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.