1

I've implemented this MVC pattern into my system :

http://www.oracle.com/technetwork/articles/javase/index-142890.html

Everything is good and dandy, I have different views and they talk to the controller when they need to put changes into the model or get called upon when changes are reflected int he model.

Now, I need this new view which uses a JTable. I've decided to extend by model's as AbstractTableModels, now only am I not sure if this is right, but the Java website proposes this to bind the model to the table:

public TableDemo() {
    ...
   JTable table = new JTable(new MyTableModel());
   ...
}

This just feels wrong, I don't have a reference to my model in my view, so how am I supposed to give a model from my view to the JTable? I could create a ;getModel; method in my controller for this special case, but still I don't know if there's a better way to deal with this.

Thanks

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Patrick.SE
  • 4,444
  • 5
  • 34
  • 44

1 Answers1

2

Your approach is correct; EnvTableTest is an example. The table's getModel() method will return your TableModel. See also this related answer.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045