as many other persons, I want my JTable being actualized after adding rows. Here you can see the fragments of my code.

ArrayList<> foundR = new ArrayList<FoundResult>();

JTable resultsTable = new JTable();
AbstractTableModel resultsModel = new FoundResultTableModel(foundR);//<- model which contains FoundResults as rows
JScrollPane scroller = new JScrollPane();

resultsTable.setModel(resultsModel);
scroller.add(resultsTable);
this.add(scroller, BorderLayout.CENTER);// a big panel which contains scroller and other components

Then a add ActionListener that uses following method:

foundR.clear();
foundR.addAll( ...);//<- so the foundR ArrayList is refreshed
resultsModel.fireTableDataChanged();
resultsModel.fireTableStructureChanged();

rowCount of results Model shows that the model is refreshed (the number of rows differes from the previeous variant), but the table still doesn't appear. I tried to insert resultsTable.repaint() but it also dind't help.

UDP(NB) I discovered, that the problem is concentrated in this scroller Panel.

If I add the table directly to the big panel it is refreshed (but I cannot see all the results, since I cannot scroll down)

 this.add(resultsTable, BorderLayout.CENTER); 

If I use a scroller, nothing is shown. Do you know why?

有帮助吗?

解决方案 2

Add this to your code,

resultsTable.revalidate();

Since your model has been changed but the change in model should be notified to the table also.

其他提示

Just recreate the model and set it to your table.

foundR.clear();
foundR.addAll( ...);//<- so the foundR ArrayList is refreshed
AbstractTableModel resultsModel = new FoundResultTableModel(foundR);
resultsTable.setModel(resultsModel);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top