Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to exclude certain columns from a prefilled object from the db module to a model?

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
In the code below, you see that some columns are excluded because they will not be needed somewhere
in my program (and somewhere else they are needed).
I would like to make a universal method so that it can be reused. But when I map these objects
to JTable using the constructor of DefaultTableModel, they somehow would include all columns that
are queried. Can I just exclude some of them to suit the JTable model where appropriate?
Thank you
Jack

 
K. Tsang
Bartender
Posts: 3502
14
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it better to not get those unused data from the Employee? The table model having the complete data from the table is somewhat a good thing because you never know when what is needed and when it's not needed.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello K Tsang,
K. Tsang wrote:
Would it better to not get those unused data from the Employee?

So I should use different SQLs + methods to present different JTable's?
Thanks
Jack
 
K. Tsang
Bartender
Posts: 3502
14
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To keep things simple I think you can keep getting all the columns for Employee class. But in the table model just get the attributes you need (eg overriding the getColumn() if I remembered correctly).

Since this is getting towards more Swing stuff, I shall move to that forum.
 
Rob Camick
Ranch Hand
Posts: 2612
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I just exclude some of them to suit the JTable model where appropriate?


Remove the TableColumn from the TableColumnModel of the JTable. The data will still be contained in the TableModel, but the column will not be displayed in the view (JTable).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic