APIdia Launch Partner
Top Description Methods
javax.swing.table

public Interface TableModel

Known Direct Implementers
javax.swing.table.AbstractTableModel
Imports
javax.swing.*, javax.swing.event.*

The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model.

The JTable can be set up to display any data model which implements the TableModel interface with a couple of lines of code:

     TableModel myData = new MyTableModel();
     JTable table = new JTable(myData);
 

For further documentation, see Creating a Table Model in The Java Tutorial.

Author
Philip Milne
See Also
JTable

Method Summary

Modifier and TypeMethod and Description
public void
addTableModelListener(TableModelListener
the TableModelListener
l
)

Adds a listener to the list that is notified each time a change to the data model occurs.

public Class<?>

Returns:

the common ancestor class of the object values in the model.
getColumnClass
(int
the index of the column
columnIndex
)

Returns the most specific superclass for all the cell values in the column.

public int

Returns:

the number of columns in the model
getColumnCount
()

Returns the number of columns in the model.

public String

Returns:

the name of the column
getColumnName
(int
the index of the column
columnIndex
)

Returns the name of the column at columnIndex.

public int

Returns:

the number of rows in the model
getRowCount
()

Returns the number of rows in the model.

public Object

Returns:

the value Object at the specified cell
getValueAt
(int
the row whose value is to be queried
rowIndex
,
int
the column whose value is to be queried
columnIndex
)

Returns the value for the cell at columnIndex and rowIndex.

public boolean

Returns:

true if the cell is editable
isCellEditable
(int
the row whose value to be queried
rowIndex
,
int
the column whose value to be queried
columnIndex
)

Returns true if the cell at rowIndex and columnIndex is editable.

public void
removeTableModelListener(TableModelListener
the TableModelListener
l
)

Removes a listener from the list that is notified each time a change to the data model occurs.

public void
setValueAt(Object
the new value
aValue
,
int
the row whose value is to be changed
rowIndex
,
int
the column whose value is to be changed
columnIndex
)

Sets the value in the cell at columnIndex and rowIndex to aValue.

Method Detail

addTableModelListenerback to summary
public void addTableModelListener(TableModelListener l)

Adds a listener to the list that is notified each time a change to the data model occurs.

Parameters
l:TableModelListener

the TableModelListener

getColumnClassback to summary
public Class<?> getColumnClass(int columnIndex)

Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

Parameters
columnIndex:int

the index of the column

Returns:Class<?>

the common ancestor class of the object values in the model.

getColumnCountback to summary
public int getColumnCount()

Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Returns:int

the number of columns in the model

See Also
getRowCount
getColumnNameback to summary
public String getColumnName(int columnIndex)

Returns the name of the column at columnIndex. This is used to initialize the table's column header name.

Note

this name does not need to be unique; two columns in a table can have the same name.

Parameters
columnIndex:int

the index of the column

Returns:String

the name of the column

getRowCountback to summary
public int getRowCount()

Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Returns:int

the number of rows in the model

See Also
getColumnCount
getValueAtback to summary
public Object getValueAt(int rowIndex, int columnIndex)

Returns the value for the cell at columnIndex and rowIndex.

Parameters
rowIndex:int

the row whose value is to be queried

columnIndex:int

the column whose value is to be queried

Returns:Object

the value Object at the specified cell

isCellEditableback to summary
public boolean isCellEditable(int rowIndex, int columnIndex)

Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

Parameters
rowIndex:int

the row whose value to be queried

columnIndex:int

the column whose value to be queried

Returns:boolean

true if the cell is editable

See Also
setValueAt
removeTableModelListenerback to summary
public void removeTableModelListener(TableModelListener l)

Removes a listener from the list that is notified each time a change to the data model occurs.

Parameters
l:TableModelListener

the TableModelListener

setValueAtback to summary
public void setValueAt(Object aValue, int rowIndex, int columnIndex)

Sets the value in the cell at columnIndex and rowIndex to aValue.

Parameters
aValue:Object

the new value

rowIndex:int

the row whose value is to be changed

columnIndex:int

the column whose value is to be changed

See Also
getValueAt, isCellEditable