File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Repaint/Refresh a Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Repaint/Refresh a Table" Watch "Repaint/Refresh a Table" New topic
Author

Repaint/Refresh a Table

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: May 06, 2001
Posts: 31
You try to use tablename.validate() before repaint().
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: May 06, 2001
Posts: 31
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

Joined: Aug 09, 2001
Posts: 4
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Repaint/Refresh a Table