javax.swing.table

Interface TableModel

public interface TableModel

A TableModel is a two dimensional data structure that can store arbitrary Object instances, usually for the purpose of display in a {@link javax.swing.JTable} component. Individual objects can be accessed by specifying the row index and column index for the object. Each column in the model has a name associated with it.

The {@link DefaultTableModel} class provides one implementation of this interface.

Method Summary
voidaddTableModelListener(TableModelListener listener)
Adds a listener to the model.
Class<?>getColumnClass(int columnIndex)
Returns the Class for all Object instances in the specified column.
intgetColumnCount()
Returns the number of columns in the model.
StringgetColumnName(int columnIndex)
Returns the name of a column in the model.
intgetRowCount()
Returns the number of rows in the model.
ObjectgetValueAt(int rowIndex, int columnIndex)
Returns the value (Object) at a particular cell in the table.
booleanisCellEditable(int rowIndex, int columnIndex)
Returns true if the cell is editable, and false otherwise.
voidremoveTableModelListener(TableModelListener listener)
Removes a listener from the model.
voidsetValueAt(Object aValue, int rowIndex, int columnIndex)
Sets the value at a particular cell in the table.

Method Detail

addTableModelListener

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

Parameters: listener the listener.

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.

getColumnCount

public int getColumnCount()
Returns the number of columns in the model.

Returns: The column count

getColumnName

public String getColumnName(int columnIndex)
Returns the name of a column in the model.

Parameters: columnIndex the column index.

Returns: The column name.

getRowCount

public int getRowCount()
Returns the number of rows in the model.

Returns: The row count.

getValueAt

public Object getValueAt(int rowIndex, int columnIndex)
Returns the value (Object) at a particular cell in the table.

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

Returns: The value at the specified cell.

isCellEditable

public boolean isCellEditable(int rowIndex, int columnIndex)
Returns true if the cell is editable, and false otherwise.

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

Returns: true if editable, false otherwise.

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Removes a listener from the model.

Parameters: listener the listener.

setValueAt

public void setValueAt(Object aValue, int rowIndex, int columnIndex)
Sets the value at a particular cell in the table.

Parameters: aValue the value (null permitted). rowIndex the row index. columnIndex the column index.