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

Abstract and Default  RSS feed

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
I have Jtable and to have its model,i'm given two options DefaultTableModel or AbstractTableModel.But my question is on what circumstances i've to decide which of these to be chosen
can any body give me a clear picture of this?
Thanx in advance
Prashu
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read in the API that AbstractTableModel provides "management of listeners and provides some conveniences for generating TableModelEvents and dispatching them to the listeners. To create a concrete TableModel as a subclass of AbstractTableModel you need only provide implementations for the following three methods:
public int getRowCount();
public int getColumnCount();
public Object getValueAt(int row, int column);
"

The protected eventListener field holds the TableModelListeners that will be notified of TableModelEvents with the AbstracTableModel.fireTableXX(...) methods. They are added or removed with the add/RemoveTableModelListener(...) methods.
When overriding setValueAt(...) a call to the proper fireTableXX methods ensures that all the registered listeners will be notified of the change. This is important becuase one of the listeners is the object in charge of drawing the table on the screen. If we do not notify a programatic change in the content of the table, we won't see it through the table on the screen.
DefaultTableModel extends from AbstractTableModel, thus provides you the same benefits plus a default implementation that can be instantiated. it uses a Vector to hold the data. This is not considered to be very efficient with large amount of data. But it's ok otherwise.
Notice how the API for DefaultTableModel specifies that each of the methods modifying the content of the table notify such change to the listeners.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!