Refresh dynamically a Jtable
843805Jan 8 2006 — edited Jan 18 2006Hello everybody (I'm new to this forum)
I've put a Jtable inside an e-mail client, in order to display such things like sender, date, subject and so on on each row.
Reading all the e-mails is a slow process, so I want the Jtable to be refreshed each time I read an e-mail, just like this:
private static DefaultTableModel model = new DefaultTableModel();
private static JTable Elenco = new JTable(model);
private static JScrollPane scrollPane;
...
scrollPane = new JScrollPane(Elenco);
scrollPane.setPreferredSize(new Dimension(400,200));
panel.add(scrollPane,BorderLayout.CENTER);
...
if (i > Elenco.getRowCount()) {model.addRow(new Object[] {null,null,null,null,null});}
Elenco.setValueAt(mittente, i-1, 0);
Elenco.setValueAt(data, i-1, 1);
Elenco.setValueAt(soggetto, i-1, 2);
//now it should appear the new row!
and so on.
When the previous code executes, the Jtable is never refreshed, other than other textareas (in which I show, for example, the number of the e-mail being retrieved). When ALL the e-mail are finished, the Jtable is refreshed once and for all, that is NOT what I want.
I tried things like repaint(), revalidate(), fireDataTableChanged() and many others, but nothing seems to work.
I think I'm missing something obvious and simple, but what?
Anyone any idea?
Thanks
Andrea Carta