Until now I had different model classes for the appropriate Java Swing component, for instance I have several TableModel
for several JTable
. Every JTable
has its own TableModel
. The TableModel
is based on one object (Model
), giving all the required data. Something like this:
public class MyTableModel extends AbstractTableModel {
Model model;
But now I would like to make a change. My interface offers the possibility of multiple instances of Model
. So my question is, what should I do?
- instantiate multiple objects from
MyTable
- change dynamically the current reference to the model upon user interaction
So the basic problem I am facing: I want to use the same JTable
with the same TableModel
. Should I use multiple TableModel
or should I use changing references to the data source?
Similar question:
I want to offer multiple tabs, they change the instance of the underlying model. The do not change the type, but the current instance - meaning, the data changes.
Should I now:
- instantiate multiple objects of the view components? For instance instantiate for every available model an own
JTable
,JPanel
,JScrollPane
object? - change dynamically by listening to change events on the tabbed pane the reference of the underyling model