This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm in doubt about my TableModel. I'm trying to make the GUI independent of database columns, but in my DB interface there isn't a "getSchema()" method. So I'm having a trouble in discovery the columns names in order to show in them my JTable.
I was thinking in a solution� I�m thinking about creating a new Interface that extends the DB interface and that defines a �public String getSchema()� method. My Data class would implement this new interface.
Can I do that? Does any one know a better solution?
You should ask yourself the question if you want to use the field names from the database as column headers in your GUI in the first place. By mere incident, the names in the supplied files are quite readable. But imagine that the database designer had opted for field names such as CntrNm or numEmployees, would you still want to show these in your GUI?
Let your GUI layer determine the look of your application!
SCJP 1.4, SCJD
Joined: Jul 21, 2005
Very good point! I didn't realize that. But I still use the database column names and take as an assumption that database column names will be feasible enough to be used in GUI. That will make my application more flexible.
It really is a bad design to use database column names in the GUI. One improvement on using database column names is to use a resource file in your GUI. In Java, resource files map one string to another. So, you can use the database column names in this file, and map them to the display string.
Here is some code from a resource file which I am currently using (not for the SCJD project, for something at work)
So instead of using "CM_LABEL_ACTIVE", you would use "CustomerID" and map it to "Customer ID". Your GUI app could search for the resource, and only use the database name for the column if you don't find it in the resource file. You could even automatically add a help label which is mapped to help text about the column, i.e. "CustomerID_HELP" could map to a string which explains the required format of the customer ID. Again, you could automatically search for this.
I don't think you need to do any of this for the assignment, just a suggestion if you want to do it the way you are proposing.
Joined: Jul 21, 2005
Ok, i understood. I'm going to make a resource file and my application will search for the column name in this file. If it does not find the mapped string then it will user the real column name.
Thanks for your attention and help! [ July 22, 2005: Message edited by: Samuel Pessorrusso ]