I have a swing
applet that contains a JTable within a JScrollpane. As the data is added at the end i need the new records to be visible. For this I set my TableModel listener move the scrollpane accordingly. But i always find that the table displays upto to last but one row. On clicking the scrollpane i find that i can see one more row at the bottom. My code is as below. Am i missing something or going wrong some where?
public void tableChanged(javax.swing.event.TableModelEvent event) {
if (event.getType() != TableModelEvent.INSERT) { return; }
final int row = event.getLastRow();
table.scrollRectToVisible(table.getCellRect(applet.table.getRowCount(), 0, true));
}
}
// i tried different variations of the last statement like
using setRowselection() before the statement.
using table.scrollRectToVisible(new Rectangle(0,table.getRowHeight()*(row),c.getWidth(),table.getRowHeight()));
Appreciate your comments.