Show TOC

TableViewModelLocate this document in the navigation structure

public interface TableViewModel

All known implementing classes: DefaultTableViewModel, JCOTableViewModel

The TableViewModel interface specifies the methods the TableView will use to interrogate a tabular data model. The tableView can be set up to display any data model which implements the TableViewModel interface.

The TableView model uses vectors to supply the tableView with data. Visible columns are a subset of the data in your model.

The absolute position in the data source has to be calculated by the application.

Method

Description

Argument

Return value

addColumn

Adds a column with the specified name to the visible columns.

(java.lang.String colNam)

TableColumn

addKeyColumn

Adds a key column.

(int columnIndex)

void

getColumnAt

Returns the column for the specified index.

(int columnIndex)

TableColumn

getColumnCount

Returns the number of columns in the model.

()

int

getColumnName

Returns the name of the column for the specified index.

(int columnIndex)

java.lang.String

getColumns

Returns a vector to the visible columns.

()

java.util.Vector

getKeyColumn

Returns the key column.

()

IndexedLinkedList

getRowCount

Returns the number of rows in the model.

()

int

getValueAt

Returns the value of the cell for the specified column and row index.

(int rowInd, int colInd)

AbstractDataType

getValueAt

Returns the value of the cell for the specified column and row index.

(int rowInd, java.lang.String colKey)

AbstractDataType

removeColumn

Removes a visible column. The data source is not effected.

(java.lang.String columnName)

void

setColumnName

Sets the name of the column for the specified columnIndex to the specified columnName.

(java.lang.String colNam, int columnIndex)

void

setKeyColumn

Sets the key column for the model.

(int columnIndex)

void

setValueAt

Sets the value for the specified location.

(AbstractDataType aVal, int rowInd, int columnInd)

void

Example

    //  Create a new table model with three columns and add data:
    private DefaultTableViewModel createNewTable
                                  (DefaultTableViewModel model) {
        Vector data = createData();
        Vector colName = new Vector();
        /* Define column names */
        colName.addElement("1stColumn");
        colName.addElement("2ndColumn");
        colName.addElement("3rdColumn");
        model = new DefaultTableViewModel(data, colName);
        return model;
    }
    private Vector createData() {
        Vector dataVec = new Vector();
        Vector retVector = new Vector();

        /* 1st entry */
        dataVec.addElement("Row 1, Column 1");
        dataVec.addElement("Row 1, Column 2");
        dataVec.addElement("Row 1, Column 3");
        retVector.addElement(dataVec);

        /* 2nd entry */
        dataVec = new Vector();
        dataVec.addElement("Row 2, Column 1");
        dataVec.addElement("Row 2, Column 2");
        dataVec.addElement("Row 2, Column 3");
        retVector.addElement(dataVec);

        /* more entries */
        .
        .
        return retVector;
    }

            

Related Topics

Using beans and models