src/share/classes/javax/swing/table/DefaultTableModel.java
Print this page
@@ -71,11 +71,17 @@
* <code>Object</code> values.
*/
protected Vector<Vector<Object>> dataVector;
/** The <code>Vector</code> of column identifiers. */
- protected Vector<Object> columnIdentifiers;
+ @SuppressWarnings("rawtypes")
+ protected Vector columnIdentifiers;
+ // Unfortunately, for greater source compatibility this Vector is
+ // being left raw. The Vector is read as well as written so using
+ // Vector<?> is not suitable and using Vector<Object> (without
+ // adding copying of input Vectors), would disallow existing code
+ // that used, say, a Vector<String> as an input parameter.
//
// Constructors
//
@@ -154,11 +160,11 @@
* @param columnNames <code>vector</code> containing the names
* of the new columns
* @see #getDataVector
* @see #setDataVector
*/
- public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) {
+ public DefaultTableModel(Vector<Vector<Object>> data, Vector<?> columnNames) {
setDataVector(data, columnNames);
}
/**
* Constructs a <code>DefaultTableModel</code> and initializes the table
@@ -218,11 +224,11 @@
* @param dataVector the new data vector
* @param columnIdentifiers the names of the columns
* @see #getDataVector
*/
public void setDataVector(Vector<Vector<Object>> dataVector,
- Vector<Object> columnIdentifiers) {
+ Vector<?> columnIdentifiers) {
this.dataVector = nonNullVector(dataVector);
this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount());
fireTableStructureChanged();
}
@@ -482,11 +488,11 @@
* @param columnIdentifiers vector of column identifiers. If
* <code>null</code>, set the model
* to zero columns
* @see #setNumRows
*/
- public void setColumnIdentifiers(Vector<Object> columnIdentifiers) {
+ public void setColumnIdentifiers(Vector<?> columnIdentifiers) {
setDataVector(dataVector, columnIdentifiers);
}
/**
* Replaces the column identifiers in the model. If the number of
@@ -548,10 +554,11 @@
* <code>tableChanged</code> notification message to all the listeners.
*
* @param columnName the identifier of the column being added
* @param columnData optional data of the column being added
*/
+ @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers
public void addColumn(Object columnName, Vector<Object> columnData) {
columnIdentifiers.addElement(columnName);
if (columnData != null) {
int columnSize = columnData.size();
if (columnSize > getRowCount()) {
@@ -650,12 +657,11 @@
* @return the value Object at the specified cell
* @exception ArrayIndexOutOfBoundsException if an invalid row or
* column was given
*/
public Object getValueAt(int row, int column) {
- Vector<Object> rowVector = dataVector.elementAt(row);
- return rowVector.elementAt(column);
+ return dataVector.elementAt(row).elementAt(column);
}
/**
* Sets the object value for the cell at <code>column</code> and
* <code>row</code>. <code>aValue</code> is the new value. This method
@@ -666,12 +672,11 @@
* @param column the column whose value is to be changed
* @exception ArrayIndexOutOfBoundsException if an invalid row or
* column was given
*/
public void setValueAt(Object aValue, int row, int column) {
- Vector<Object> rowVector = dataVector.elementAt(row);
- rowVector.setElementAt(aValue, column);
+ dataVector.elementAt(row).setElementAt(aValue, column);
fireTableCellUpdated(row, column);
}
//
// Protected Methods