I have a vector with HashMap elements. I want to put it in a table and every HashTable value must be in column with HashTable key column-title. So elements with key "key1" must appear on table column with name "key1".
The problem is when I try to add/remove columns of table with setHash()
function.
I pass a String[] with more/fewer elements and when this function run the fireTableStructureChanged()
java throws like crazy.
I don't understand where is the problem. Can you help me please?
The implementation of Table Model is here:
public class ResizableTableModel extends AbstractTableModel {
protected DataSource src;
protected String[] hash;
//......................
public void setHash(String[] hash) {
this.hash = hash;
fireTableStructureChanged(); // THROWS!
}
public ArrayList getData() { return src.getData(); }
public int getColumnCount() { return hash.length; }
public int getRowCount() { return getData() == null ? 0 : getData().size(); }
public String getColumnName(int col) { return hash[col]; }
public boolean isCellEditable(int row, int col) { return true; }
public Object getValueAt(int row, int col) {
try {
return ((HashMap) getData().get(row)).get(hash[col]);
} catch (Exception e) {
return null;
}
}
public void setValueAt(Object obj, int row, int col) {
try {
//...................
} catch (Exception e) {}
fireTableDataChanged();
}
}
don't to remove Columns from XxxTableModel,
remove Column from JTables view only, data are still stored and accesible in XxxTableModel