• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTables  RSS feed

 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick general question for some of you more advanced guys. When using JTables do you generally use DefaultTableModel or extend AbstractTableModel and why? I always do the latter.

ms
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like writing my own table model (AbstractTableModel) because it is necessary if you want to display or interact with the table in an "expected manner."

Of course this is just my opinion, however I find that most of my tables are populated with strings, ints, doubles, booleans, etc. I want my doubles displayed to a particular precision. I want my numbers right justified, I want my boolean variables to show up as check marks and not as text, I want my text left justified, etc.

Also, most of my tables are NOT for display uses only. There is typically some user interaction with them. I want to be able to pick and choose which columns are editable. I want a drop down list for some columns and to force numerical entries in others.

The uses of writing your own table model are seemingly endless.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally I use AbstractTableModel. This is mainly because I usually don't want to use a Vector of Vectors to store my cell value objects.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!