JavaTM 2 Platform
Standard Edition

javax.swing.table
Class AbstractTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
Direct Known Subclasses:
DefaultTableModel

public abstract class AbstractTableModel
extends Object
implements TableModel, Serializable

This abstract class provides default implementations for most of the methods in the TableModel interface. It takes care of the management of listners and provides some conveniences for generating TableModelEvents and dispatching them to the listeners. To create a concrete TableModel as a sublcass 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);
  

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.

See Also:
Serialized Form

Field Summary
protected  EventListenerList listenerList
          List of listeners
 
Constructor Summary
AbstractTableModel()
           
 
Method Summary
 void addTableModelListener(TableModelListener l)
          Add a listener to the list that's notified each time a change to the data model occurs.
 int findColumn(String columnName)
          Convenience method for locating columns by name.
 void fireTableCellUpdated(int row, int column)
          Notify all listeners that the value of the cell at (row, column) has been updated.
 void fireTableChanged(TableModelEvent e)
          Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 void fireTableDataChanged()
          Notify all listeners that all cell values in the table's rows may have changed.
 void fireTableRowsDeleted(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted.
 void fireTableRowsInserted(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted.
 void fireTableRowsUpdated(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated.
 void fireTableStructureChanged()
          Notify all listeners that the table's structure has changed.
 Class getColumnClass(int columnIndex)
          Returns Object.class by default
 String getColumnName(int column)
          Return a default name for the column using spreadsheet conventions: A, B, C, ...
 boolean isCellEditable(int rowIndex, int columnIndex)
          This default implementation returns false for all cells
 void removeTableModelListener(TableModelListener l)
          Remove a listener from the list that's notified each time a change to the data model occurs.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
List of listeners
Constructor Detail

AbstractTableModel

public AbstractTableModel()
Method Detail

getColumnName

public String getColumnName(int column)
Return a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc.
Specified by:
getColumnName in interface TableModel
Tags copied from interface: TableModel
Parameters:
columnIndex - the index of column
Returns:
the name of the column

findColumn

public int findColumn(String columnName)
Convenience method for locating columns by name. Implementation is naive so this should be overridden if this method is to be called often. This method is not in the TableModel interface and is not used by the JTable.

getColumnClass

public Class getColumnClass(int columnIndex)
Returns Object.class by default
Specified by:
getColumnClass in interface TableModel
Tags copied from interface: TableModel
Returns:
the common ancestor class of the object values in the model.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
This default implementation returns false for all cells
Specified by:
isCellEditable in interface TableModel
Tags copied from interface: TableModel
Parameters:
rowIndex - the row whose value is to be looked up
columnIndex - the column whose value is to be looked up
Returns:
true if the cell is editable.
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
This empty implementation is provided so users don't have to implement this method if their data model is not editable.
Specified by:
setValueAt in interface TableModel
Tags copied from interface: TableModel
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed
See Also:
TableModel.getValueAt(int, int), TableModel.isCellEditable(int, int)

addTableModelListener

public void addTableModelListener(TableModelListener l)
Add a listener to the list that's notified each time a change to the data model occurs.
Specified by:
addTableModelListener in interface TableModel
Parameters:
l - the TableModelListener

removeTableModelListener

public void removeTableModelListener(TableModelListener l)
Remove a listener from the list that's notified each time a change to the data model occurs.
Specified by:
removeTableModelListener in interface TableModel
Parameters:
l - the TableModelListener

fireTableDataChanged

public void fireTableDataChanged()
Notify all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table, ie. the order of the columns is assumed to be the same.
See Also:
TableModelEvent, EventListenerList

fireTableStructureChanged

public void fireTableStructureChanged()
Notify all listeners that the table's structure has changed. The number of columns in the table, and the names and types of the new columns may be different from the previous state. If the JTable recieves this event and its autoCreateColumnsFromModel flag is set it discards any TableColumns that it had and reallocates default ones in the order they appear in the model. This is the same as calling setModel(TableModel) on the JTable.
See Also:
TableModelEvent, EventListenerList

fireTableRowsInserted

public void fireTableRowsInserted(int firstRow,
                                  int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted.
See Also:
TableModelEvent, EventListenerList

fireTableRowsUpdated

public void fireTableRowsUpdated(int firstRow,
                                 int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated.
See Also:
TableModelEvent, EventListenerList

fireTableRowsDeleted

public void fireTableRowsDeleted(int firstRow,
                                 int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted.
See Also:
TableModelEvent, EventListenerList

fireTableCellUpdated

public void fireTableCellUpdated(int row,
                                 int column)
Notify all listeners that the value of the cell at (row, column) has been updated.
See Also:
TableModelEvent, EventListenerList

fireTableChanged

public void fireTableChanged(TableModelEvent e)
Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
See Also:
addTableModelListener(javax.swing.event.TableModelListener), TableModelEvent, EventListenerList

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.