javax.swing.table
Class AbstractTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
DefaultTableModel

public abstract class AbstractTableModel
extends Object
implements TableModel, Serializable

A base class that can be used to create implementations of the TableModel interface.

See Also:
Serialized Form

Field Summary
protected  EventListenerList listenerList
          Storage for the listeners registered with this model.
 
Constructor Summary
AbstractTableModel()
          Creates a default instance.
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Adds a listener to the table model.
 int findColumn(String columnName)
          Return the index of the specified column, or -1 if there is no column with the specified name.
 void fireTableCellUpdated(int row, int column)
          Sends a TableModelEvent to all registered listeners to inform them that a single cell has been updated.
 void fireTableChanged(TableModelEvent event)
          Sends the specified event to all registered listeners.
 void fireTableDataChanged()
          Sends a TableModelEvent to all registered listeners to inform them that the table data has changed.
 void fireTableRowsDeleted(int firstRow, int lastRow)
          Sends a TableModelEvent to all registered listeners to inform them that some rows have been deleted from the model.
 void fireTableRowsInserted(int firstRow, int lastRow)
          Sends a TableModelEvent to all registered listeners to inform them that some rows have been inserted into the model.
 void fireTableRowsUpdated(int firstRow, int lastRow)
          Sends a TableModelEvent to all registered listeners to inform them that some rows have been updated.
 void fireTableStructureChanged()
          Sends a TableModelEvent to all registered listeners to inform them that the table structure has changed.
 Class<?> getColumnClass(int columnIndex)
          Returns the Class for all Object instances in the specified column.
 String getColumnName(int columnIndex)
          Returns the name of the specified column.
<T extends EventListener>
T[]
getListeners(Class<T> listenerType)
          Returns an array of listeners of the given type that are registered with this model.
 TableModelListener[] getTableModelListeners()
          Returns an array containing the listeners that have been added to the table model.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the specified cell is editable, and false if it is not.
 void removeTableModelListener(TableModelListener listener)
          Removes a listener from the table model so that it will no longer receive notification of changes to the table model.
 void setValueAt(Object value, int rowIndex, int columnIndex)
          Sets the value of the given cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
getColumnCount, getRowCount, getValueAt
 

Field Detail

listenerList

protected EventListenerList listenerList
Storage for the listeners registered with this model.

Constructor Detail

AbstractTableModel

public AbstractTableModel()
Creates a default instance.

Method Detail

getColumnName

public String getColumnName(int columnIndex)
Returns the name of the specified column. This method generates default names in a sequence (starting with column 0): A, B, C, ..., Z, AA, AB, AC, ..., AZ, BA, BB, BC, and so on. Subclasses may override this method to allow column names to be specified on some other basis.

Specified by:
getColumnName in interface TableModel
Parameters:
columnIndex - the column index.
Returns:
The name of the column.

findColumn

public int findColumn(String columnName)
Return the index of the specified column, or -1 if there is no column with the specified name.

Parameters:
columnName - the name of the column (null not permitted).
Returns:
The index of the column, -1 if not found.
Throws:
NullPointerException - if columnName is null.
See Also:
getColumnName(int)

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Returns the Class for all Object instances in the specified column.

Specified by:
getColumnClass in interface TableModel
Parameters:
columnIndex - the column index.
Returns:
The class.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the specified cell is editable, and false if it is not. This implementation returns false for all arguments, subclasses should override the method if necessary.

Specified by:
isCellEditable in interface TableModel
Parameters:
rowIndex - the row index of the cell.
columnIndex - the column index of the cell.
Returns:
false.

setValueAt

public void setValueAt(Object value,
                       int rowIndex,
                       int columnIndex)
Sets the value of the given cell. This implementation ignores all arguments and does nothing, subclasses should override the method if necessary.

Specified by:
setValueAt in interface TableModel
Parameters:
value - the new value (null permitted).
rowIndex - the row index of the cell.
columnIndex - the column index of the cell.

addTableModelListener

public void addTableModelListener(TableModelListener listener)
Adds a listener to the table model. The listener will receive notification of all changes to the table model.

Specified by:
addTableModelListener in interface TableModel
Parameters:
listener - the listener.

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Removes a listener from the table model so that it will no longer receive notification of changes to the table model.

Specified by:
removeTableModelListener in interface TableModel
Parameters:
listener - the listener to remove.

getTableModelListeners

public TableModelListener[] getTableModelListeners()
Returns an array containing the listeners that have been added to the table model.

Returns:
Array of TableModelListener objects.
Since:
1.4

fireTableDataChanged

public void fireTableDataChanged()
Sends a TableModelEvent to all registered listeners to inform them that the table data has changed.


fireTableStructureChanged

public void fireTableStructureChanged()
Sends a TableModelEvent to all registered listeners to inform them that the table structure has changed.


fireTableRowsInserted

public void fireTableRowsInserted(int firstRow,
                                  int lastRow)
Sends a TableModelEvent to all registered listeners to inform them that some rows have been inserted into the model.

Parameters:
firstRow - the index of the first row.
lastRow - the index of the last row.

fireTableRowsUpdated

public void fireTableRowsUpdated(int firstRow,
                                 int lastRow)
Sends a TableModelEvent to all registered listeners to inform them that some rows have been updated.

Parameters:
firstRow - the index of the first row.
lastRow - the index of the last row.

fireTableRowsDeleted

public void fireTableRowsDeleted(int firstRow,
                                 int lastRow)
Sends a TableModelEvent to all registered listeners to inform them that some rows have been deleted from the model.

Parameters:
firstRow - the index of the first row.
lastRow - the index of the last row.

fireTableCellUpdated

public void fireTableCellUpdated(int row,
                                 int column)
Sends a TableModelEvent to all registered listeners to inform them that a single cell has been updated.

Parameters:
row - the row index.
column - the column index.

fireTableChanged

public void fireTableChanged(TableModelEvent event)
Sends the specified event to all registered listeners.

Parameters:
event - the event to send.

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns an array of listeners of the given type that are registered with this model.

Parameters:
listenerType - the listener class.
Returns:
An array of listeners (possibly empty).