Methods Summary |
---|
public void | addColumn(java.lang.Object columnName)Adds a column to the model. The new column will have the
identifier 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.
addColumn(columnName, (Vector)null);
|
public void | addColumn(java.lang.Object columnName, java.util.Vector columnData)Adds a column to the model. The new column will have the
identifier 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.
columnIdentifiers.addElement(columnName);
if (columnData != null) {
int columnSize = columnData.size();
if (columnSize > getRowCount()) {
dataVector.setSize(columnSize);
}
justifyRows(0, getRowCount());
int newColumn = getColumnCount() - 1;
for(int i = 0; i < columnSize; i++) {
Vector row = (Vector)dataVector.elementAt(i);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
|
public void | addColumn(java.lang.Object columnName, java.lang.Object[] columnData)Adds a column to the model. The new column will have the
identifier 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(columnName, convertToVector(columnData));
|
public void | addRow(java.util.Vector rowData)Adds a row to the end of the model. The new row will contain
null values unless rowData is specified.
Notification of the row being added will be generated.
insertRow(getRowCount(), rowData);
|
public void | addRow(java.lang.Object[] rowData)Adds a row to the end of the model. The new row will contain
null values unless rowData is specified.
Notification of the row being added will be generated.
addRow(convertToVector(rowData));
|
protected static java.util.Vector | convertToVector(java.lang.Object[] anArray)Returns a vector that contains the same objects as the array.
if (anArray == null) {
return null;
}
Vector v = new Vector(anArray.length);
for (int i=0; i < anArray.length; i++) {
v.addElement(anArray[i]);
}
return v;
|
protected static java.util.Vector | convertToVector(java.lang.Object[][] anArray)Returns a vector of vectors that contains the same objects as the array.
if (anArray == null) {
return null;
}
Vector v = new Vector(anArray.length);
for (int i=0; i < anArray.length; i++) {
v.addElement(convertToVector(anArray[i]));
}
return v;
|
private static int | gcd(int i, int j)
return (j == 0) ? i : gcd(j, i%j);
|
public int | getColumnCount()Returns the number of columns in this data table.
return columnIdentifiers.size();
|
public java.lang.String | getColumnName(int column)Returns the column name.
Object id = null;
// This test is to cover the case when
// getColumnCount has been subclassed by mistake ...
if (column < columnIdentifiers.size() && (column >= 0)) {
id = columnIdentifiers.elementAt(column);
}
return (id == null) ? super.getColumnName(column)
: id.toString();
|
public java.util.Vector | getDataVector()Returns the 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);
return dataVector;
|
public int | getRowCount()Returns the number of rows in this data table.
return dataVector.size();
|
public java.lang.Object | getValueAt(int row, int column)Returns an attribute value for the cell at row
and column .
Vector rowVector = (Vector)dataVector.elementAt(row);
return rowVector.elementAt(column);
|
public void | insertRow(int row, java.util.Vector rowData)Inserts a row at row in the model. The new row
will contain null values unless rowData
is specified. Notification of the row being added will be generated.
dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1);
fireTableRowsInserted(row, row);
|
public void | insertRow(int row, java.lang.Object[] rowData)Inserts a row at row in the model. The new row
will contain null values unless rowData
is specified. Notification of the row being added will be generated.
insertRow(row, convertToVector(rowData));
|
public boolean | isCellEditable(int row, int column)Returns true regardless of parameter values.
return true;
|
private void | justifyRows(int from, int to)
// Sometimes the DefaultTableModel is subclassed
// instead of the AbstractTableModel by mistake.
// Set the number of rows for the case when getRowCount
// is overridden.
dataVector.setSize(getRowCount());
for (int i = from; i < to; i++) {
if (dataVector.elementAt(i) == null) {
dataVector.setElementAt(new Vector(), i);
}
((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
}
|
public void | moveRow(int start, int end, int to)Moves one or more rows from the inclusive range 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
int shift = to - start;
int first, last;
if (shift < 0) {
first = to;
last = end;
}
else {
first = start;
last = to + end - start;
}
rotate(dataVector, first, last + 1, shift);
fireTableRowsUpdated(first, last);
|
public void | newDataAvailable(javax.swing.event.TableModelEvent event)Equivalent to fireTableChanged .
fireTableChanged(event);
|
public void | newRowsAdded(javax.swing.event.TableModelEvent e)Ensures that the new rows have the correct number of columns.
This is accomplished by using the 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.
justifyRows(e.getFirstRow(), e.getLastRow() + 1);
fireTableChanged(e);
|
private static java.util.Vector | newVector(int size)
Vector v = new Vector(size);
v.setSize(size);
return v;
|
private static java.util.Vector | nonNullVector(java.util.Vector v)
return (v != null) ? v : new Vector();
|
public void | removeRow(int row)Removes the row at row from the model. Notification
of the row being removed will be sent to all the listeners.
dataVector.removeElementAt(row);
fireTableRowsDeleted(row, row);
|
private static void | rotate(java.util.Vector v, int a, int b, int shift)
int size = b - a;
int r = size - shift;
int g = gcd(size, r);
for(int i = 0; i < g; i++) {
int to = i;
Object tmp = v.elementAt(a + to);
for(int from = (to + r) % size; from != i; from = (to + r) % size) {
v.setElementAt(v.elementAt(a + from), a + to);
to = from;
}
v.setElementAt(tmp, a + to);
}
|
public void | rowsRemoved(javax.swing.event.TableModelEvent event)Equivalent to fireTableChanged .
fireTableChanged(event);
|
public void | setColumnCount(int columnCount)Sets the number of columns in the model. If the new size is greater
than the current size, new columns are added to the end of the model
with null cell values.
If the new size is less than the current size, all columns at index
columnCount and greater are discarded.
columnIdentifiers.setSize(columnCount);
justifyRows(0, getRowCount());
fireTableStructureChanged();
|
public void | setColumnIdentifiers(java.util.Vector columnIdentifiers)Replaces the column identifiers in the model. If the number of
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.
setDataVector(dataVector, columnIdentifiers);
|
public void | setColumnIdentifiers(java.lang.Object[] newIdentifiers)Replaces the column identifiers in the model. If the number of
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.
setColumnIdentifiers(convertToVector(newIdentifiers));
|
public void | setDataVector(java.util.Vector dataVector, java.util.Vector columnIdentifiers)Replaces the current dataVector instance variable
with the new Vector of rows, dataVector .
Each row is represented in dataVector as a
Vector of Object values.
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.
this.dataVector = nonNullVector(dataVector);
this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount());
fireTableStructureChanged();
|
public void | setDataVector(java.lang.Object[][] dataVector, java.lang.Object[] columnIdentifiers)Replaces the value in the 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.
setDataVector(convertToVector(dataVector), convertToVector(columnIdentifiers));
|
public void | setNumRows(int rowCount)Obsolete as of Java 2 platform v1.3. Please use setRowCount instead.
int old = getRowCount();
if (old == rowCount) {
return;
}
dataVector.setSize(rowCount);
if (rowCount <= old) {
fireTableRowsDeleted(rowCount, old-1);
}
else {
justifyRows(old, rowCount);
fireTableRowsInserted(old, rowCount-1);
}
|
public void | setRowCount(int rowCount)Sets the number of rows in the model. If the new size is greater
than the current size, new rows are added to the end of the model
If the new size is less than the current size, all
rows at index rowCount and greater are discarded.
setNumRows(rowCount);
|
public void | setValueAt(java.lang.Object aValue, int row, int column)Sets the object value for the cell at column and
row . aValue is the new value. This method
will generate a tableChanged notification.
Vector rowVector = (Vector)dataVector.elementAt(row);
rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, column);
|