wood burning stoves 2.0*
The moose likes Java in General and the fly likes Concerning Custom Table Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Concerning Custom Table Model" Watch "Concerning Custom Table Model" New topic
Author

Concerning Custom Table Model

Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
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.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
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)
 
wood burning stoves
 
subject: Concerning Custom Table Model
 
Similar Threads
Please Help - JTable!
? JTable getColumnName
? File I/O (and-or) for each loop
I don't understand why my JTable will not display data
Help with AbstractTableModel - Please!!