JTable stores rows which can be added, deleted, shuffled, dynamically. In my implementation row represent a Download
, whose progress can be dynamically updated, by passing value of one of the unique attribute called id
. But how do I map id
with actual row?
Iterating over the column is not efficient approach. Is there any way to dynamically synchronize Hashmap<ID,Object[]>
with JTable
, such that given a key I can update corresponding row, and vice versa?
private dftTasks=new DefaultTableModel();
public void addTask(String type, String name, int progress, int sessionID) {
Object[] rowData={type,name,new Integer(progress),new Integer(sessionID)};
dftTasks.addRow(rowData);
}
public void updateProgress(int sessionID, int progress) {
int i = dftTasks.getRow(sessionID); //<--alternative to this method
dftTasks.setValueAt(new Integer(progress), i, 2); //2nd column=Progress
}