I have extended the AbstractTableModel to suit my requirements. Now this table can be altered by other methods of my GUI. I want the table to scroll to the currently edited cell into view. To do this, I think I have to first get the JViewport of the current JComponent, but I see no method by which I can achieve this? How do I achieve this?
I have already done this when I have used the default JTable, but how do I do this when we extend AbstractTableModel?
Models are designed to store data and notify views when the data has changed. It notifies the view of a change in data by firing events. It is the responsibility of the view to listen for these events. Therefore the model never knows directly what view is being updated. This type of functionality should NOT be part of the model.
One approach might be to use a TableModelListener. You can create a TableModelListner with the table as a paramenter. Then when data is changed the listener will be notified. You can then invoke table.scrollRectToVisible(...) on the table. However, with this approach you can't distinquish between edits that have been applied directly through the TableModel versus udates that have been done through the JTable itself.