Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Repaint/Refresh a Table

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to automatically refresh or repaint a JTable
when a row has been deleted by pressing a button on a GUI.
I tried tablename.repaint()but no joy.
Any help much appreciated.
Thanks
Suhail
 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You try to use tablename.validate() before repaint().
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
I tried to use tablename.validate() before using table.repaint() but there is no change. I press a button to update a row or delete a row and the change is not reflected in the table. I still have to re-run the program to view the change.
Strange. There is probably a way of doing this but I just don't know what.
Anyway. Thanks for the suggestion.
Suhail
Originally posted by Luong Nguyen:
You try to use tablename.validate() before repaint().

 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suhail,
I don't know what the TableModel is used. If the TableModel is a DefaultTableModel, you try to the following code. Otherwise, you must change the model in the code with the model of your table.
class DelAction implements ActionListener {
int row = m_table.getSelectedRow();
DefaultTableModel model = (DefaultTableModel)m_table.getModel();
model.removeRow(row);
m_table.tableChanged(new TableModelEvent(model, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
m_table.repaint();
}
Luong.
 
Shishir Parikh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
U dont need to repaint the table.
All u need to do is refresh your TableModel.
Use fireTableRowDeleted() of AbstractTableModel if u know the row no. deleted. If you dont, then use fireTableChanged().
Hope thats what you were looking for,
Njoy,
SHISH.

Originally posted by suhail sarwar:
Does anyone know how to automatically refresh or repaint a JTable
when a row has been deleted by pressing a button on a GUI.
I tried tablename.repaint()but no joy.
Any help much appreciated.
Thanks
Suhail

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic