TableModel
that uses a Vector
of Vectors
to store the cell value objects. Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans
package. Please see java.beans.XMLEncoder.
Field Detail |
protected Vector dataVector
Vector
of Vectors
of Object
values.protected Vector columnIdentifiers
Vector
of column identifiers.Constructor Detail |
public DefaultTableModel()
DefaultTableModel
which is a table of zero columns and zero rows.public DefaultTableModel(int rowCount, int columnCount)
DefaultTableModel
with rowCount
and columnCount
of null
object values.rowCount
- the number of rows the table holdscolumnCount
- the number of columns the table holdspublic DefaultTableModel(Vector columnNames, int rowCount)
DefaultTableModel
with as many columns as there are elements in columnNames
and rowCount
of null
object values. Each column's name will be taken from the columnNames
vector.columnNames
- vector
containing the names of the new columns; if this is null
then the model has no columnsrowCount
- the number of rows the table holdspublic DefaultTableModel(Object[] columnNames, int rowCount)
DefaultTableModel
with as many columns as there are elements in columnNames
and rowCount
of null
object values. Each column's name will be taken from the columnNames
array.columnNames
- array
containing the names of the new columns; if this is null
then the model has no columnsrowCount
- the number of rows the table holdspublic DefaultTableModel(Vector data, Vector columnNames)
DefaultTableModel
and initializes the table by passing data
and columnNames
to the setDataVector
method.data
- the data of the tablecolumnNames
- vector
containing the names of the new columnspublic DefaultTableModel(Object[][] data, Object[] columnNames)
DefaultTableModel
and initializes the table by passing data
and columnNames
to the setDataVector
method. The first index in the Object[][]
array is the row index and the second is the column index.data
- the data of the tablecolumnNames
- the names of the columnsMethod Detail |
public Vector getDataVector()
Vector
of Vectors
that contains the table's data values. The vectors contained in the outer vector are each a single row of values. In other words, to get to the cell at row 1, column 5: ((Vector)getDataVector().elementAt(1)).elementAt(5);
public void setDataVector(Vector dataVector, Vector columnIdentifiers)
dataVector
instance variable with the new Vector of rows, dataVector
. columnIdentifiers
are the names of the new columns. The first name in columnIdentifiers
is mapped to column 0 in dataVector
. Each row in dataVector
is adjusted to match the number of columns in columnIdentifiers
either by truncating the Vector
if it is too long, or adding null
values if it is too short. Note that passing in a null
value for dataVector
results in unspecified behavior, an possibly an exception.
dataVector
- the new data vectorcolumnIdentifiers
- the names of the columnspublic void setDataVector(Object[][] dataVector, Object[] columnIdentifiers)
dataVector
instance variable with the values in the array dataVector
. The first index in the Object[][]
array is the row index and the second is the column index. columnIdentifiers
are the names of the new columns.dataVector
- the new data vectorcolumnIdentifiers
- the names of the columnspublic void newDataAvailable(TableModelEvent event)
fireTableChanged
.event
- the change eventpublic void newRowsAdded(TableModelEvent e)
setSize
method in Vector
which truncates vectors which are too long, and appends null
s if they are too short. This method also sends out a tableChanged
notification message to all the listeners.e
- this TableModelEvent
describes where the rows were added. If null
it assumes all the rows were newly addedpublic void rowsRemoved(TableModelEvent event)
fireTableChanged
.event
- the change eventpublic void setNumRows(int rowCount)
setRowCount
instead.public void setRowCount(int rowCount)
rowCount
and greater are discarded. public void addRow(Vector rowData)
null
values unless rowData
is specified. Notification of the row being added will be generated.rowData
- optional data of the row being addedpublic void addRow(Object[] rowData)
null
values unless rowData
is specified. Notification of the row being added will be generated.rowData
- optional data of the row being addedpublic void insertRow(int row, Vector rowData)
row
in the model. The new row will contain null
values unless rowData
is specified. Notification of the row being added will be generated.row
- the row index of the row to be insertedrowData
- optional data of the row being addedArrayIndexOutOfBoundsException
- if the row was invalidpublic void insertRow(int row, Object[] rowData)
row
in the model. The new row will contain null
values unless rowData
is specified. Notification of the row being added will be generated.row
- the row index of the row to be insertedrowData
- optional data of the row being addedArrayIndexOutOfBoundsException
- if the row was invalidpublic void moveRow(int start, int end, int to)
start
to end
to the to
position in the model. After the move, the row that was at index start
will be at index to
. This method will send a tableChanged
notification message to all the listeners.
Examples of moves:1. moveRow(1,3,5); a|B|C|D|e|f|g|h|i|j|k - before a|e|f|g|h|B|C|D|i|j|k - after
2. moveRow(6,7,1); a|b|c|d|e|f|G|H|i|j|k - before a|G|H|b|c|d|e|f|i|j|k - after
start
- the starting row index to be movedend
- the ending row index to be movedto
- the destination of the rows to be movedArrayIndexOutOfBoundsException
- if any of the elements would be moved out of the table's rangepublic void removeRow(int row)
row
from the model. Notification of the row being removed will be sent to all the listeners.row
- the row index of the row to be removedArrayIndexOutOfBoundsException
- if the row was invalidpublic void setColumnIdentifiers(Vector columnIdentifiers)
newIdentifier
s is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifier
s is less than the current number of columns, all the extra columns at the end of a row are discarded. columnIdentifiers
- vector of column identifiers. If null
, set the model to zero columnspublic void setColumnIdentifiers(Object[] newIdentifiers)
newIdentifier
s is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifier
s is less than the current number of columns, all the extra columns at the end of a row are discarded. newIdentifiers
- array of column identifiers. If null
, set the model to zero columnspublic void setColumnCount(int columnCount)
null
cell values. If the new size is less than the current size, all columns at index columnCount
and greater are discarded.columnCount
- the new number of columns in the modelpublic void addColumn(Object columnName)
columnName
, which may be null. This method will send a tableChanged
notification message to all the listeners. This method is a cover for addColumn(Object, Vector)
which uses null
as the data vector.columnName
- the identifier of the column being addedpublic void addColumn(Object columnName, Vector columnData)
columnName
, which may be null. columnData
is the optional vector of data for the column. If it is null
the column is filled with null
values. Otherwise, the new data will be added to model starting with the first element going to row 0, etc. This method will send a tableChanged
notification message to all the listeners.columnName
- the identifier of the column being addedcolumnData
- optional data of the column being addedpublic void addColumn(Object columnName, Object[] columnData)
columnName
. columnData
is the optional array of data for the column. If it is null
the column is filled with null
values. Otherwise, the new data will be added to model starting with the first element going to row 0, etc. This method will send a tableChanged
notification message to all the listeners.public int getRowCount()
public int getColumnCount()
public String getColumnName(int column)
columnIdentifiers
. If columnIdentifiers
does not have an entry for this index, returns the default name provided by the superclasspublic boolean isCellEditable(int row, int column)
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queriedpublic Object getValueAt(int row, int column)
row
and column
.row
- the row whose value is to be queriedcolumn
- the column whose value is to be queriedArrayIndexOutOfBoundsException
- if an invalid row or column was givenpublic void setValueAt(Object aValue, int row, int column)
column
and row
. aValue
is the new value. This method will generate a tableChanged
notification.aValue
- the new value; this can be nullrow
- the row whose value is to be changedcolumn
- the column whose value is to be changedArrayIndexOutOfBoundsException
- if an invalid row or column was givenprotected static Vector convertToVector(Object[] anArray)
anArray
- the array to be convertedanArray
is null
, returns null
protected static Vector convertToVector(Object[][] anArray)
anArray
- the double array to be convertedanArray
is null
, returns null