Save This Page
Home » openjdk-7 » javax » swing » table » [javadoc | source]
javax.swing.table
public class: DefaultTableModel [javadoc | source]
java.lang.Object
   javax.swing.table.AbstractTableModel
      javax.swing.table.DefaultTableModel

All Implemented Interfaces:
    java$io$Serializable, TableModel, Serializable

This is an implementation of TableModel that uses a Vector of Vectors to store the cell value objects.

Warning: DefaultTableModel returns a column class of Object. When DefaultTableModel is used with a TableRowSorter this will result in extensive use of toString, which for non-String data types is expensive. If you use DefaultTableModel with a TableRowSorter you are strongly encouraged to override getColumnClass to return the appropriate type.

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 Summary
protected  Vector dataVector    The Vector of Vectors of Object values. 
protected  Vector columnIdentifiers    The Vector of column identifiers. 
Fields inherited from javax.swing.table.AbstractTableModel:
listenerList
Constructor:
 public DefaultTableModel() 
 public DefaultTableModel(int rowCount,
    int columnCount) 
 public DefaultTableModel(Vector columnNames,
    int rowCount) 
    Constructs a 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.
    Parameters:
    columnNames - vector containing the names of the new columns; if this is null then the model has no columns
    rowCount - the number of rows the table holds
    Also see:
    setDataVector
    setValueAt
 public DefaultTableModel(Object[] columnNames,
    int rowCount) 
    Constructs a 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.
    Parameters:
    columnNames - array containing the names of the new columns; if this is null then the model has no columns
    rowCount - the number of rows the table holds
    Also see:
    setDataVector
    setValueAt
 public DefaultTableModel(Vector data,
    Vector columnNames) 
    Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector method.
    Parameters:
    data - the data of the table, a Vector of Vectors of Object values
    columnNames - vector containing the names of the new columns
    Also see:
    getDataVector
    setDataVector
 public DefaultTableModel(Object[][] data,
    Object[] columnNames) 
    Constructs a 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.
Method from javax.swing.table.DefaultTableModel Summary:
addColumn,   addColumn,   addColumn,   addRow,   addRow,   convertToVector,   convertToVector,   getColumnCount,   getColumnName,   getDataVector,   getRowCount,   getValueAt,   insertRow,   insertRow,   isCellEditable,   moveRow,   newDataAvailable,   newRowsAdded,   removeRow,   rowsRemoved,   setColumnCount,   setColumnIdentifiers,   setColumnIdentifiers,   setDataVector,   setDataVector,   setNumRows,   setRowCount,   setValueAt
Methods from javax.swing.table.AbstractTableModel:
addTableModelListener,   findColumn,   fireTableCellUpdated,   fireTableChanged,   fireTableDataChanged,   fireTableRowsDeleted,   fireTableRowsInserted,   fireTableRowsUpdated,   fireTableStructureChanged,   getColumnClass,   getColumnName,   getListeners,   getTableModelListeners,   isCellEditable,   removeTableModelListener,   setValueAt
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.table.DefaultTableModel Detail:
 public  void addColumn(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.
 public  void addColumn(Object columnName,
    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.
 public  void addColumn(Object columnName,
    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.
 public  void addRow(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.
 public  void addRow(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.
 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.
 public int getColumnCount() 
    Returns the number of columns in this data table.
 public String getColumnName(int column) 
    Returns the column name.
 public 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);

 public int getRowCount() 
    Returns the number of rows in this data table.
 public Object getValueAt(int row,
    int column) 
    Returns an attribute value for the cell at row and column.
 public  void insertRow(int row,
    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.
 public  void insertRow(int row,
    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.
 public boolean isCellEditable(int row,
    int column) 
    Returns true regardless of parameter values.
 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

 public  void newDataAvailable(TableModelEvent event) 
    Equivalent to fireTableChanged.
 public  void newRowsAdded(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 nulls if they are too short. This method also sends out a tableChanged notification message to all the listeners.
 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.
 public  void rowsRemoved(TableModelEvent event) 
    Equivalent to fireTableChanged.
 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.
 public  void setColumnIdentifiers(Vector columnIdentifiers) 
    Replaces the column identifiers in the model. If the number of newIdentifiers 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 newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

 public  void setColumnIdentifiers(Object[] newIdentifiers) 
    Replaces the column identifiers in the model. If the number of newIdentifiers 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 newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

 public  void setDataVector(Vector dataVector,
    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.

 public  void setDataVector(Object[][] dataVector,
    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.
 public  void setNumRows(int rowCount) 
    Obsolete as of Java 2 platform v1.3. Please use setRowCount instead.
 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.

 public  void setValueAt(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.