I have re-structured my GUI according to the MVC pattern, but I am not sure how to populate a JTable in my view. So far, my code is:
VIEW:
public class GUIview extends JFrame {
...
// set Table Inputs info
public void setTableInfo(List<Object[]> listTable) {
for (int i = 0; i < listTable.size(); i++) {
Object[] tempArray = listTable.get(i);
((DefaultTableModel) getTableModel()).insertRow(i, tempArray);
}
}
CONTROLLER.
public class GUIcontroller {
...
m_view.setTableInfo(m_model.getList());
MODEL
public class GUImodel {
...
public List<Object[]> getList() {
return resultsList;
}
I would like to code as close as possible to MVC. Is this the most suitable approach? I mean, the View should not contain code just for rendering the view. I am thinking about move the "for" loop to the controller, and then just call a view-function for the insertRow. Is is better?