I've spent quite a while trying to figure out a way of adding a new row to a JTable, initially by looking for methods on the following model:
TableModel model = new DefaultTableModel(data, tabs);
However, some quick searching lead me to find that the method addRow was within the DefaultTableModel class instead. So changing it to the following was successful:
DefaultTableModel model = new DefaultTableModel(data, tabs);
However, I've created many successful programs where I have had a pre-built array using TabelModel, so I'm a bit confused as to why I needed to switch to DefaultTableModel to achieve this solution and if there is a reason and a purpose for each? E.g.: Is it okay to simple use a TabelModel with a pre-built array and why does my above implementation of TableModel not come with the methods to add new data?
Thanks!
If you must use your own collection as a nucleus for your table model, then so be it, but then you'll want to extend AbstractTableModel and create your own addRow method that adds the data to the model, and (here's the critical part) that fires the appropriate data change notification method of AbstractTableModel.