Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel Inheritance  RSS feed

 
Ajit Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Guys,
I saw in some examples that the TableModel for a JTable is inherited from AbstractTableModel.
When do we have to extend AbstractTableModel. I believe, the AbstractTableModel does provide the functionality required for a JTable?
Thanks
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The TableModel for JTable does derive from AbstractTableModel, but not directly. JTable uses DefaultTableModel, which gladly works with any kind of cell content that converts to a String.
You'd extend AbstractTableModel yourself if you wanted to provide support in a way that DefaultTableModel would easily allow. As an abstract class, AbstractTableModel always has to be subclassed. DefaultTableModel just saves you the work of managing the most likely content (String data) by yourself.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Ajit Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
concentrating on the second paragraph of your reply.
What could the possible reason/scenario where we would need to extend the abstratTableModel ourselves?
If the defaultTableModel does offer all the functionality, why does anyone have to extend explicitly?
Your answer is greatly appreciated.
thanks
 
Arvind PV
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i would like to inform you that using AbstractTableModel you get lot of freedom and specially when u are using a lot of jtables in an application. u can infact have classes to be used as datatypes and give a lot more functionality to the jtable, like show and hiding of columns, filtering of rows, sorting of rows, etc..the list is very long..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!