我有一個帶有HashMap元素的向量。 我想把它放在一個表中,並且每個HashTable值必須在HashTable鍵列標題的列中。 所以具有鍵「key1」的元素必須出現在名稱爲「key1」的表列上。從定製AbstractTableModel中添加/刪除更多列到JTable
問題是當我嘗試添加/刪除表的列與setHash()
函數。 我通過一個字符串[]與更多/更少的元素,當這個函數運行fireTableStructureChanged()
Java拋出瘋狂。
我不明白問題在哪裏。你能幫我嗎?
表模型的實現是在這裏:
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();
}
}
HashMap缺少索引,必須使用List代替 – mKorbel 2013-04-10 08:23:09
_我不明白問題出在哪裏。並且任何人都很難找出問題出在哪裏,因爲你的代碼是不完整的,你不會告訴我們你得到了什麼異常,也不知道它出現在哪一行。考慮發佈[SSCCE](http://sscce.org) – 2013-04-10 08:30:42