• 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

Concerning Custom Table Model

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't figure out how to fill my ArrayList ( table model ) when the program starts.
I thought about doing it from the constructor, but not only is it not working, I'm
not so sure I am going down the right path with this. Here is the TableModel class.
If I can get the following line in the constructor
to work, would this be a good way to go?



The readFile() method is supposed to return an ArrayList of ItemCarrier objects.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should do it like the DefaultTableModel does. That is you should be able to build the model mutliple ways:

a) Pass in the ArrayList as part of the constructor
b) Reset the model by adding to method to accept the ArrayList
c) Dynamically change the model with add/remove methods.

The model should not be responsible for reading data from a file because then it becomes a single purpose model.

For a generic model you check out my RowTableModel. You can then extend it to provide the appropriate constructor and implement your getValueAt() and setValueAt() methods (or you could just use the BeanTableModel which can also be found at the above link)
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic