Hello all,
I have a JTable, and I would like to refresh its display each time I add a new row.
I am currently using the following code, but as the table size is growing, it becomes slower and slower.
{
tableModel.addRow(newRow);
//scroll viewport to last added row
scrollBottomTable(tableLog);
}
private void scrollBottomTable(JTable scrollTable) {
int index = scrollTable.getRowCount() - 1;
if (index > 0) {
//Scroll automatically the viewport to the last row added
JViewport viewport = (JViewport) scrollTable.getParent();
java.awt.Rectangle rect = scrollTable.getCellRect(index, 0, true);
java.awt.Point pos = viewport.getViewPosition();
rect.translate(-pos.x, -pos.y);
viewport.scrollRectToVisible(rect);
//Update Graphics
scrollTable.update(scrollTable.getGraphics());
}
}
Does anyone has a most improved way to update graphically my table as I add rows ?