| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||
java.lang.Object
|
+----java.awt.swing.table.AbstractTableModel
|
+----java.awt.swing.table.DefaultTableModel
Note:
The DefaultTableModel's API contains the methods addColumn(),
removeColumn(), but not methods to insert a column at an index
nor methods to move the columns. This is because JTable does
not display the columns based on the order of the columns in
this model. So rearranging them here doesn't do much. See
the column ordering methods in TableColumnModel.
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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
| Field Summary | |
| Vector | columnIdentifiers
|
| Vector | dataVector
|
| Fields inherited from class java.awt.swing.table.AbstractTableModel |
| listenerList |
| Constructor Summary | |
| DefaultTableModel()
|
|
| DefaultTableModel(int numColumns,
int numRows)
|
|
| DefaultTableModel(Vector columnIds,
int numRows)
|
|
| DefaultTableModel(Object[] columnIds,
int numRows)
|
|
| DefaultTableModel(Vector data,
Vector columnIds)
|
|
| DefaultTableModel(Object[][] data,
Object[] columnIds)
|
|
| Method Summary | |
| void | addColumn(Object columnIdentifier)
|
| void | addColumn(Object columnIdentifier,
Vector columnData)
|
| void | addColumn(Object columnIdentifier,
Object[] columnData)
|
| void | addRow(Vector rowData)
|
| void | addRow(Object[] rowData)
|
| static Vector | convertToVector(Object[] anArray)
|
| static Vector | convertToVector(Object[][] anArray)
|
| int | getColumnCount()
|
| String | getColumnName(int column)
|
| Vector | getDataVector()
|
| int | getRowCount()
|
| Object | getValueAt(int row,
int column)
|
| void | insertRow(int row,
Vector rowData)
|
| void | insertRow(int row,
Object[] rowData)
|
| boolean | isCellEditable(int row,
int column)
|
| void | moveRow(int startIndex,
int endIndex,
int toIndex)
|
| void | newDataAvailable(TableModelEvent event)
|
| void | newRowsAdded(TableModelEvent event)
|
| void | removeRow(int row)
|
| void | rowsRemoved(TableModelEvent event)
|
| void | setColumnIdentifiers(Vector newIdentifiers)
|
| void | setColumnIdentifiers(Object[] newIdentifiers)
|
| void | setDataVector(Vector newData,
Vector columnIds)
|
| void | setDataVector(Object[][] newData,
Object[] columnIds)
|
| void | setNumRows(int newSize)
|
| void | setValueAt(Object aValue,
int row,
int column)
|
| Methods inherited from class java.awt.swing.table.AbstractTableModel |
| addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, isCellEditable, removeTableModelListener, setValueAt |
| Methods inherited from class java.lang.Object |
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Vector dataVector
protected Vector columnIdentifiers
| Constructor Detail |
public DefaultTableModel()
public DefaultTableModel(int numColumns,
int numRows)
numColumns
- The number of columns the table holds
numRows
- The number of rows the table holds
public DefaultTableModel(Vector columnIds,
int numRows)
columnIds
- Vector containing identifier objects
to be used to identify the columns. If this
null then the model has no columns
numRows
- The number of rows the table holds
public DefaultTableModel(Object[] columnIds,
int numRows)
columnIds
- Array containing identifier objects
to be used to identify the columns. If this
null then the model has no columns
numRows
- The number of rows the table holds
public DefaultTableModel(Vector data,
Vector columnIds)
data
- The data of the table
columnIds
- Vector containing identifier objects
to be used to identify the columns.
public DefaultTableModel(Object[][] data,
Object[] columnIds)
data
- The data of the table
columnIds
- Array containing identifier objects
to be used to identify the columns.
| Method Detail |
public Vector getDataVector()
((Vector)getDataVector().elementAt(1)).elementAt(5);
You can directly alter the returned Vector. You can change the cell values, the number of rows, but you may not change the number of columns in the model. If you need to alter the number of columns in the model, you can do so with addColumn(), removeColumn(), or the setDataVector() methods. Once you have finished modifying the dataVector, you must inform the model of the new data using the newDataAvailable(), rowsRemoved() or the newRowsAdded() methods. Depending on which one of the three best describes the changes made. These methods will give the model a chance to modify its internal variables based upon the new data vector. The new data methods will also generate the appropriate TableModelListener messages to notify any listeners of this model.
public void setDataVector(Vector newData,
Vector columnIds)
The size of the columnIds vector must equal the size of the newData vector. If columnIds is null then it will reuse the currect vector of column identifiers. Finally, this method calls newDataAvailable() to generate the appropriate notification.
newData
- The new data vector
columnIds
- The corresponding column identifiers for
the new data vector
public void setDataVector(Object[][] newData,
Object[] columnIds)
newData
- The new data array
columnIds
- The corresponding column identifiers for
the new data array
public void newDataAvailable(TableModelEvent event)
If event is null or if the number of rows in dataVector is different from numRows, then it will assume all the data in dataVector is new or updated. It will recalculate numRows, and will generate the correct TableModelEvent to send out with the nofication.
public void newRowsAdded(TableModelEvent event)
public void rowsRemoved(TableModelEvent event)
public void setColumnIdentifiers(Vector newIdentifiers)
newIdentifiers
- Vector of column identifiers. A null means
setting the model to zero columns
public void setColumnIdentifiers(Object[] newIdentifiers)
newIdentifiers
- Array of column identifiers. A null means
setting the model to zero columns
public void setNumRows(int newSize)
newSize
- the new number of rows
public void addColumn(Object columnIdentifier)
columnIdentifier
- the identifier of the column being added
public void addColumn(Object columnIdentifier,
Vector columnData)
columnIdentifier
- the identifier of the column being added
columnData
- optional data of the column being added
public void addColumn(Object columnIdentifier,
Object[] columnData)
columnIdentifier
- the identifier of the column being added
columnData
- optional data of the column being added
public void addRow(Vector rowData)
rowData
- optional data of the row being added
public void addRow(Object[] rowData)
rowData
- optional data of the row being added
public void insertRow(int row,
Vector rowData)
row
- the row index of the row to be inserted
rowData
- optional data of the row being added
public void insertRow(int row,
Object[] rowData)
row
- the row index of the row to be inserted
rowData
- optional data of the row being added
public void moveRow(int startIndex,
int endIndex,
int toIndex)
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 moved
endIndex
- the ending row index to be moved
toIndex
- the destination of the rows to be moved
public void removeRow(int row)
row
- the row index of the row to be removed
public int getRowCount()
public int getColumnCount()
public String getColumnName(int column)
public boolean isCellEditable(int row,
int column)
row
- the row whose value is to be looked up
column
- the column whose value is to be looked up
public Object getValueAt(int row,
int column)
row
- the row whose value is to be looked up
column
- the column whose value is to be looked up
public void setValueAt(Object aValue,
int row,
int column)
aValue
- the new value. This can be null.
row
- the row whose value is to be changed
column
- the column whose value is to be changed
protected static Vector convertToVector(Object[] anArray)
protected static Vector convertToVector(Object[][] anArray)
| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||