ciao!
ho una JTable che prende i dati da un file json.
il mio problema è che quando aggiorno il file, la JTable non si aggiorna.
o meglio, si aggiorna solo quando rilancio il programma.
quando lancio l'aggiornamento faccio questo:
in pratica scarico diversi file e poi lancio il metodo che riempie la JTable (riempiTable()):codice:public void createConnection() { try { if (CheckConnection.check()) { jsb.launchService("all_books"); jsb.launchService("all_authors"); jsb.launchService("all_editors"); jsb.launchService("graph_authors"); jsb.launchService("graph_editors"); jsb.download(UrlAndPath.JSON_LIBRI); jsb.download(UrlAndPath.JSON_AUTORI); jsb.download(UrlAndPath.JSON_EDITORI); jsb.download(UrlAndPath.GRAPH_AUTHORS); jsb.download(UrlAndPath.GRAPH_EDITORS); riempiTable(); riempiCombo(); resetTxt(); tableData.requestFocus(); } else { JOptionPane.showMessageDialog(null, "No connection"); } } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
i dati sono aggiornati, anche perchè quando riavvio il programma la JTable ha tutti i dati precisi.codice:private void riempiTable() { try { MyTableModel newModel = (MyTableModel) tableData.getModel(); while (newModel.getRowCount() > 0) { newModel.removeRow(0); } ArrayList<ArrayList<String>> map = jsonRead.getAllBooks(); map.stream().forEach((map1) -> { ((MyTableModel) tableData.getModel()).addRow(map1.toArray()); }); textCount.setText(String.valueOf(tableData.getRowCount())); txtQuickSearch.setEditable(true); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
qualche idea??

Rispondi quotando