• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel Vs DefaultTableModel

 
Alex Qiu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone kindly tell me why choose AbstractTableModel but not DefaultTableModel as the model in the table ?
I just can't finger out why , thanks in advance .
 
Kees Pieters
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using DefaultTable model, because it provides most implementations I need. I just need to override one or two methods. The abstractTableModel was much more basic
CU
Kees
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,
The DefaultTableModel is the model that a JTable will use if you don't supply one. Also, DefaultTableModel uses a Vector of Vectors to store the data. Quite frankly, that ain't a very good model for most uses. On the other hand, AbstractTableModel, though involving a little more work, gives you the option of choosing what your underlying data is. The minimum you have to do is implement:

to make your model functional and you probably will want to overide:

To return the correct Class of each column.
Hope this helps,
Michael Morris
 
Alex Qiu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you all .
Now I know why not use DefaultTableModel ,
It cost much and it is not flexible .
Now I have my own DataTableModel which extends AbstractTableModel , it works well .
Thanks , Michael the Great .
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael the Great

A better moniker would be Michael the Lesser who owes a tremendous debt to Mark the Great, Peter the Greater and JavaRanch the Greatest.
Michael Morris
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"keesp"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic