javax.swing.table

Class AbstractTableModel

Implemented Interfaces:
Serializable, TableModel
Known Direct 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.
extends EventListener> T[] getListeners(Class listenerType)
Returns an array of listeners of the given type that are registered with this 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.
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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

listenerList

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

Constructor Details

AbstractTableModel

public AbstractTableModel()
Creates a default instance.

Method Details

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.

extends EventListener> T[] getListeners

public extends EventListener> T[] getListeners(Class 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).

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.

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.

fireTableDataChanged

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

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.

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.

fireTableStructureChanged

public void fireTableStructureChanged()
Sends a 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.
Specified by:
getColumnClass in interface TableModel
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.
Specified by:
getColumnName in interface TableModel
Parameters:
columnIndex - the column index.
Returns:
The name of the column.

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

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.

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.

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.

AbstractTableModel.java -- Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.