|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.table.AbstractTableModel | +--javax.swing.table.DefaultTableModel
This is an implementation of 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. A future release of Swing will provide support for long term persistence.
TableModel
,
getDataVector()
, Serialized FormField Summary | |
protected Vector |
columnIdentifiers
The Vector of column identifiers. |
protected Vector |
dataVector
The Vector of Vectors of
Object values. |
Fields inherited from class javax.swing.table.AbstractTableModel |
listenerList |
Constructor Summary | |
DefaultTableModel()
Constructs a default DefaultTableModel
which is a table of zero columns and zero rows. |
|
DefaultTableModel(int numRows,
int numColumns)
Constructs a DefaultTableModel with
numRows and numColumns of
null object values. |
|
DefaultTableModel(Object[][] data,
Object[] columnNames)
Constructs a DefaultTableModel and initializes the table
by passing data and columnNames
to the setDataVector
method. |
|
DefaultTableModel(Object[] columnNames,
int numRows)
Constructs a DefaultTableModel with as many
columns as there are elements in columnNames
and numRows of null
object values. |
|
DefaultTableModel(Vector columnNames,
int numRows)
Constructs a DefaultTableModel with as many columns
as there are elements in columnNames
and numRows of null
object values. |
|
DefaultTableModel(Vector data,
Vector columnNames)
Constructs a DefaultTableModel and initializes the table
by passing data and columnNames
to the setDataVector method. |
Method Summary | |
void |
addColumn(Object columnName)
Adds a column to the model. |
void |
addColumn(Object columnName,
Object[] columnData)
Adds a column to the model. |
void |
addColumn(Object columnName,
Vector columnData)
Adds a column to the model. |
void |
addRow(Object[] rowData)
Adds a row to the end of the model. |
void |
addRow(Vector rowData)
Adds a row to the end of the model. |
protected static Vector |
convertToVector(Object[] anArray)
Returns a vector that contains the same objects as the array. |
protected static Vector |
convertToVector(Object[][] anArray)
Returns a vector of vectors that contains the same objects as the array. |
int |
getColumnCount()
Returns the number of columns in this data table. |
String |
getColumnName(int column)
Returns the column name. |
Vector |
getDataVector()
Returns the Vector of Vectors
that contains the table's
data values. |
int |
getRowCount()
Returns the number of rows in this data table. |
Object |
getValueAt(int row,
int column)
Returns an attribute value for the cell at row
and column . |
void |
insertRow(int row,
Object[] rowData)
Inserts a row at row in the model. |
void |
insertRow(int row,
Vector rowData)
Inserts a row at row in the model. |
boolean |
isCellEditable(int row,
int column)
Returns true regardless of parameter values. |
void |
moveRow(int startIndex,
int endIndex,
int toIndex)
Moves one or more rows starting at startIndex
to endIndex in the model to the toIndex . |
void |
newDataAvailable(TableModelEvent event)
Equivalent to fireTableChanged . |
void |
newRowsAdded(TableModelEvent event)
Ensures that the new rows have the correct number of columns. |
void |
removeRow(int row)
Removes the row at row from the model. |
void |
rowsRemoved(TableModelEvent event)
Equivalent to fireTableChanged . |
void |
setColumnCount(int columnCount)
Sets the number of columns in the model. |
void |
setColumnIdentifiers(Object[] newIdentifiers)
Replaces the column identifiers in the model. |
void |
setColumnIdentifiers(Vector newIdentifiers)
Replaces the column identifiers in the model. |
void |
setDataVector(Object[][] newData,
Object[] columnNames)
Replaces the value in the dataVector instance
variable with the values in the array newData . |
void |
setDataVector(Vector newData,
Vector columnNames)
Replaces the current dataVector instance variable with the
new Vector of rows, newData . |
void |
setNumRows(int newSize)
Obsolete as of Java 2 platform v1.3. |
void |
setRowCount(int rowCount)
Sets the number of rows in the model. |
void |
setValueAt(Object aValue,
int row,
int column)
Sets the object value for the cell at column and
row . |
Methods inherited from class javax.swing.table.AbstractTableModel |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, removeTableModelListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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 numRows, int numColumns)
DefaultTableModel
with
numRows
and numColumns
of
null
object values.numRows
- the number of rows the table holdsnumColumns
- the number of columns the table holdssetValueAt(java.lang.Object, int, int)
public DefaultTableModel(Vector columnNames, int numRows)
DefaultTableModel
with as many columns
as there are elements in columnNames
and numRows
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 columnsnumRows
- the number of rows the table holdssetDataVector(java.util.Vector, java.util.Vector)
,
setValueAt(java.lang.Object, int, int)
public DefaultTableModel(Object[] columnNames, int numRows)
DefaultTableModel
with as many
columns as there are elements in columnNames
and numRows
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 columnsnumRows
- the number of rows the table holdssetDataVector(java.util.Vector, java.util.Vector)
,
setValueAt(java.lang.Object, int, int)
public 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 columnsgetDataVector()
,
setDataVector(java.util.Vector, java.util.Vector)
public 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 columnsgetDataVector()
,
setDataVector(java.util.Vector, java.util.Vector)
Method 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);
newDataAvailable(javax.swing.event.TableModelEvent)
,
newRowsAdded(javax.swing.event.TableModelEvent)
,
setDataVector(java.util.Vector, java.util.Vector)
public void setDataVector(Vector newData, Vector columnNames)
dataVector
instance variable with the
new Vector of rows, newData
.
columnNames
are the names
of the new columns. The first name in columnNames
is
mapped to column 0 in newData
. Each row in
newData
is adjusted to match the number of columns in columnNames
either by truncating the Vector
if it is too long,
or adding null
values if it is too short.
newData
- the new data vectorcolumnNames
- the names of the columnsnewDataAvailable(javax.swing.event.TableModelEvent)
,
getDataVector()
public void setDataVector(Object[][] newData, Object[] columnNames)
dataVector
instance
variable with the values in the array newData
.
The first index in the Object[][]
array is the row index and the second is the column index.
columnNames
are the names of the new columns.newData
- the new data vectorcolumnNames
- the names of the columnssetDataVector(Vector, Vector)
public void newDataAvailable(TableModelEvent event)
fireTableChanged
.event
- the change eventpublic void newRowsAdded(TableModelEvent event)
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.event
- this TableModelEvent
describes
where the rows were added.
If null
it assumes
all the rows were newly addedgetDataVector()
public void rowsRemoved(TableModelEvent event)
fireTableChanged
.event
- the change eventpublic void setColumnIdentifiers(Vector 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
- vector of column identifiers. If
null
, set the model
to zero columnssetNumRows(int)
public 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 columnssetNumRows(int)
public void setNumRows(int newSize)
setRowCount
instead.public void setRowCount(int rowCount)
rowCount
and greater are discarded. setColumnCount(int)
public 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 modelsetColumnCount(int)
public void addColumn(Object columnName)
columnName
. 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 addedIllegalArgumentException
- if columnName
is null
public void addColumn(Object columnName, Vector columnData)
columnName
. 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 addedIllegalArgumentException
- if columnName
is null
public 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.addColumn(Object, Vector)
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 startIndex, int endIndex, int toIndex)
startIndex
to endIndex
in the model to the toIndex
.
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|B|C|D|g|h|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
startIndex
- the starting row index to be movedendIndex
- the ending row index to be movedtoIndex
- the destination of the rows to be movedArrayIndexOutOfBoundsException
- if any of the indices
are out of range; or if endIndex
is less than startIndex
public 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 int getRowCount()
public int getColumnCount()
public String getColumnName(int column)
getColumnName
in class AbstractTableModel
columnIdentifiers
.
If columnIdentifiers
is null
or does not have an entry for this index, returns the default
name provided by the superclasspublic boolean isCellEditable(int row, int column)
isCellEditable
in class AbstractTableModel
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queriedsetValueAt(java.lang.Object, int, int)
public 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.setValueAt
in class AbstractTableModel
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
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Oracle and/or its affiliates, in the US and other countries.
Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.