In my UI I am using a JTable with a TableModel.In a update method of the implemented Observer interface i am calling the repaint method.The delete operations take place immediately while on adding a row it is not updated,but it is updated while switching through tabs( which calls another method instead of repaint)
This is code for update method:
public void update(Observable o, Object arg) {
((MyTableModel)table_.getModel()).addTableRow(row);
//addTable(row) adds the row to the dataVector that populates the JTable
//the dataVector is updated with added row
table_.repaint();
}
I wanted to know why the JTable is not getting updated
Please Note->the data Vector has the required rows including the added row
Your
addTableRowmethod should also fire an event indicating the row has been added to alert theJTableof this change. Then there is no need for therepaintcall.Take for example a look at the implementation of the
addRowmethod of theDefaultTableModel:You can clearly see that an event is fired, and no repaint needed. This is all explained in more detail in the
JTabletutorial