aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Should we use DefaultTableColumnModel with TableModel ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Should we use DefaultTableColumnModel with TableModel ?" Watch "Should we use DefaultTableColumnModel with TableModel ?" New topic
Author

Should we use DefaultTableColumnModel with TableModel ?

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
The Complete Java2 Certification Study Guide by Roberts, Heller, and Ernest wrote:
... DefaultTableColumnModel provides a standard implementation and includes event "firing" methods that broadcast changes in column behavior --- deletion, addition, order change, selection change, and margin change ... TableModel adds a layer of control on top of column objects, which allows an implementation of the interface to return information on its table --- row count, column count, and column names among them ... One aspect of model-view relationships that may take some getting used to is that the data model representations maintain column order independent of the view. When we want to rearrange data on the view level, for example, we don't want to be restricted to the model's internal arrangement of columns. We may decide we would rather have last names before first names or states before zip codes.


Hi,

I have implemented an MVC architected presentation layer in my SCJD assignment. The problem is that the data that I get from the database is ordered in a String[], and the data in my data model is ordered in the same way. My view is dependent upon the order of the data received from the data model. Did anyone else have this problem, and did you use DefaultTableColumnModel to decouple the view from the data model?

Thanks,
Harry
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

Hi Harry,

I just used my own AbstractTableModel. It was simple, easy and type safe: you have to implement a few methods and you can add your own methods (for example an add method which takes a Room-object).
And I think this kind of tableModel is more than enough for this assignment, because there is no need for "deletion, addition, order change, selection change, and margin change" of columns, so if it is not required/needed, don't do it (certainly not when it adds extra complexity in your code).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Thanks Roel,

The referenced design suggestion seemed like overkill to me, but I wanted to make sure that other designers weren't implementing this "requirement".

Best regards,
Harry
 
Don't get me started about those stupid light bulbs.
 
subject: Should we use DefaultTableColumnModel with TableModel ?