javax.swing.table

Class AbstractTableModel

public abstract class AbstractTableModel extends Object implements TableModel, Serializable

A base class that can be used to create implementations of the {@link TableModel} interface.
Field Summary
protected EventListenerListlistenerList
Storage for the listeners registered with this model.
Constructor Summary
AbstractTableModel()
Creates a default instance.
Method Summary
voidaddTableModelListener(TableModelListener listener)
Adds a listener to the table model.
intfindColumn(String columnName)
Return the index of the specified column, or -1 if there is no column with the specified name.
voidfireTableCellUpdated(int row, int column)
Sends a {@link TableModelEvent} to all registered listeners to inform them that a single cell has been updated.
voidfireTableChanged(TableModelEvent event)
Sends the specified event to all registered listeners.
voidfireTableDataChanged()
Sends a {@link TableModelEvent} to all registered listeners to inform them that the table data has changed.
voidfireTableRowsDeleted(int firstRow, int lastRow)
Sends a {@link TableModelEvent} to all registered listeners to inform them that some rows have been deleted from the model.
voidfireTableRowsInserted(int firstRow, int lastRow)
Sends a {@link TableModelEvent} to all registered listeners to inform them that some rows have been inserted into the model.
voidfireTableRowsUpdated(int firstRow, int lastRow)
Sends a {@link TableModelEvent} to all registered listeners to inform them that some rows have been updated.
voidfireTableStructureChanged()
Sends a {@link 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.
StringgetColumnName(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.
booleanisCellEditable(int rowIndex, int columnIndex)
Returns true if the specified cell is editable, and false if it is not.
voidremoveTableModelListener(TableModelListener listener)
Removes a listener from the table model so that it will no longer receive notification of changes to the table model.
voidsetValueAt(Object value, int rowIndex, int columnIndex)
Sets the value of the given cell.

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

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.

Parameters: listener the listener.

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: AbstractTableModel

fireTableCellUpdated

public void fireTableCellUpdated(int row, int column)
Sends a {@link 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.

fireTableDataChanged

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

fireTableRowsDeleted

public void fireTableRowsDeleted(int firstRow, int lastRow)
Sends a {@link 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.

fireTableRowsInserted

public void fireTableRowsInserted(int firstRow, int lastRow)
Sends a {@link 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 {@link 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.

fireTableStructureChanged

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

getColumnClass

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

Parameters: columnIndex the column index.

Returns: The class.

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.

Parameters: columnIndex the column index.

Returns: The name of the column.

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).

getTableModelListeners

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

Returns: Array of {@link TableModelListener} objects.

Since: 1.4

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.

Parameters: rowIndex the row index of the cell. columnIndex the column index of the cell.

Returns: false.

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.

Parameters: listener the listener to remove.

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.

Parameters: value the new value (null permitted). rowIndex the row index of the cell. columnIndex the column index of the cell.