• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Where TableModel goes? -- Client GUI

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
In my design, two JComboBox (Views) are hooked with DataModel (Model) (client side) through listeners. Controller (Control) deals with all inputs from JComboBox and JTable, then directly save all changes in the DataModel (Model).
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?
Any suggestion for this? Thanks.
Rick
Regards.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rick,

Originally posted by Rick Lu:
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?


I agree with your idea of having the TableModel within the view.
You could have the View getting the updates from the Model and passing them on to the TableModel. Alternatively, if your Model is Observable, you could make your TableModel an Observer, and have it receive the updates directly.
Does this give you some ideas?
Regards, Andrew
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Andrew.


You could have the View getting the updates from the Model and passing them on to the TableModel.


I think JTable is the View. But of course, I need a class (TableModel) that extends AbstractTableModel. My question is that how I can update TableModel by View? Did you mean directly getting updates from Model to JTable and passing them to TableModel? Or something else? I cannot understand this. Currently, the view - JTable gets everything from TableModel. Could you explain this from me? Confused.
Regards. Rick
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rick,
You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel, or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).
Regards, Andrew
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,


You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel,


You mean "That class" is a part of Views? To me, the role of it is not clear. I think that's my problem. Is it a part of View?

or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).


Yes, I currently use it and it works.
Thanks. Rick
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I undertand your points now, Andrew. Thanks.
Rick
Regards.
reply
    Bookmark Topic Watch Topic
  • New Topic