Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Common Model for different component

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Is it possible to use same Model object to many components.

Like say I have a Model object for Name.

Can I use the same Model object with a JComboBox, JSpinner, JList, etc......?
If yes how?

Thanks
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you can use the same model. That model will have to implement all the different interfaces for those components however (ListModel, ComboBoxModel,...).

If you create a model that conforms to all those interfaces I see no reason why you can not use the same Object/Class in them.

Hope this helps.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another, probably more apropriate design, would be to have a common model that isn't specific to any of the components (that is, doesn't implement any of the interfaces), and provide an Adapter for each component - an implementation of the appropriate interface that basically delegates all calls to the common model.
 
reply
    Bookmark Topic Watch Topic
  • New Topic