JavaFX 8: Updating the TableView after the window closes

0

I have a classifications and a classification management screen, from a library system. After registering a new classification, I would like the TableView of classifications in the management screen to be updated showing the new record. I redo the query in the database and pass the values of the new query to the list, however it does not refresh on the screen. Here I call the method to redo the query after saving the information in the database:

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

Here is where it remaps the query and arrows the items in the 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 TableView refresh method, it remaps the query in the database and brings up the right information, but it does not arrow in the TableView. Please help me: p NOTE: This same method (updateTableView) is called in the initialize of the screen, and works correctly, when I call from outside (another file) it does not work.

    
asked by anonymous 23.02.2017 / 04:08

1 answer

1

Hello, you are creating a new instance of ManageController Classes, so nothing is updated. You must pass the current instance of it to the registry controller and call the updateTableView () method from that instance. Example:

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

In the CadastroClassificationsController change your registration method to:

{Rotina que salva a informação no banco}
gerenciadorController.atualizarTableView();
    
18.03.2017 / 17:46