Using fireTableDataChanged() within a custom table extending AbstractTableModel
Posted on 2007-10-01
Product: Java, SE 6
It seems I need help.
I am using AbstractTableModel to create a custom table and when I invoke fireTableDataChanged() after editing my table data in my table model nothing seems to happen.
I thought that AbstractTableModel implicitly handles the delegation to update the view, the JTable.
It seems I am missing something in my code to help this along. I am asking you because I want to stop banging my head against a wall.
What I have done is implement the three necessary methods from the table model interface which is implemented by AbstractTableModel:
public int getColumnCount()
public int getRowCount()
public Object getValueAt(int row, int column)
as well as the getColumnName method to add columns.
Since my data model is not editable externally (directly through the cells) I decided not to implement setValueAt.
I am using a vector of vectors for my main data structure. My nested vectors hold Object types of the loan payment info.
I thought it was my data structure but I can initialize my table with data using the vector structure in the constructor of MyCustomTable. However, when i fire a change from elsewhere nothing happens(either using the code that tested the data structure and classes correctness from my constructor or the loan info.). I must be missing something and don't know what. The only other thing I haven't really considered is my JScrollPane but that really shouldn't be an issue.
What I have considered is:
1)providing my own implementation for delegation and updating the view: this seems unnecessary since the docs say its already there.
2) my datastructure: works fine in the constructor
3) where I call fireTableDataChanged(): doesn't seem to matter if i can from within class or from the JTable object, still doesn't work.
4) what i am storing: i am storing vectors of objects that are really strings(maybe cant update table with this object type?)
I hope you can help.