Search code examples
javaswingjtableabstracttablemodel

auto update jtable columns when model changes


I've got a class which implements the TableModel Interface. When I call setModel on my jTable and set my class as the model and then call jTable.updateUI();everything is fine. But in some circumstances I want to change the model with a different structure. Displaying the data still works fine but my columns are not updated. Is there a way of forcing my table to also refresh the columns from new model?


Solution

  • The model needs to fire the according event, e.g.: fireTableStructureChanged, if both the data and the structure changed.

    http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#fire