|
Copyright © 2011 Citra Technologies. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ListTableModel
The ListTableModel interface defines methods for manipulating the data of a tabular data model. It also defines methods for generating TableModelEvents and dispatching them to the listeners.
The seven fire methods inherit their names from the fire methods of AbstractTableModel abstract class. The names of these methods were chosen this way to make ListTableModel backward compatible with AbstractTableModel and DefaultTableModel.
ListTableModel assumes that the data are kept in a List structure, e.g. Vector,
ArrayList etc., as is the case with DefaultTableModel.
This list structure is returned with ListTableModel.getRows()
.
The elements in the list represent the actual row data, which can be any java object and not just
List objects.
To get a reference to a specific column of a row data, we use ListTableModel.getCellValue(Object row, int index)
.
e.g. for a DefaultTableModel this would be implemented as return ((Vector) row).get(index);
Furthermore, five additional methods manipulate the data.
These are ListTableModel.addRow(java.lang.Object)
, ListTableModel.addRows(java.util.List)
, ListTableModel.clear()
, ListTableModel.removeRow(int)
and ListTableModel.removeRows(int[])
.
The tablemodels in this library (SortTableModel, FilterTableModel and TreeTableModel) all require a ListTableModel in their constructor. Therefore, if you want to continue to use your custom tablemodel in conjunction with these classes, your tablemodel should implement the ListTableModel interface. This can be done very easily.
E.g. assuming your custom TableModel extends DefaultTableModel, you need to provide an implementation of the following methods:
public void addRow(Object row); public void addRows(List rowData); public void clear(); public List getRows(); public Object getCellValue(Object o, int index); public void removeRow(int row); public void removeRows(int[] deletedRows);, in which you most definitely would somehow manipulate the dataVector field of DefaultTableModel.
Method Summary | |
---|---|
void |
addRow(Object row)
Adds a row to the end of the model. |
void |
addRows(List addedRows)
Adds a list of rows to the end of the model. |
void |
clear()
Clears the model of any data. |
void |
fireTableCellUpdated(int row,
int column)
Notify all listeners that the value of the cell at (row, column) has been updated. |
void |
fireTableChanged(TableModelEvent e)
Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model. |
void |
fireTableDataChanged()
Notify all listeners that all cell values in the table's rows may have changed. |
void |
fireTableRowsDeleted(int firstRow,
int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted. |
void |
fireTableRowsInserted(int firstRow,
int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted. |
void |
fireTableRowsUpdated(int firstRow,
int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated. |
void |
fireTableStructureChanged()
Notify all listeners that the table's structure has changed. |
Object |
getCellValue(Object row,
int index)
Returns the Object found at index of row passed as a parameter. |
List |
getRows()
Returns the data of this tablemodel |
void |
removeRow(int row)
Removes a row from the data model |
void |
removeRows(int[] deletedRows)
Removes a few rows from the data model |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt |
Method Detail |
---|
void addRow(Object row)
row
- the row being addedvoid addRows(List addedRows)
addedRows contains objects representing the actual rows being added. e.g. Vector, for DefaultTableModel.
addedRows
- the rows being added.void clear()
void fireTableCellUpdated(int row, int column)
void fireTableChanged(TableModelEvent e)
void fireTableDataChanged()
void fireTableRowsDeleted(int firstRow, int lastRow)
void fireTableRowsInserted(int firstRow, int lastRow)
void fireTableRowsUpdated(int firstRow, int lastRow)
void fireTableStructureChanged()
setModel(TableModel)
on the JTable.
Object getCellValue(Object row, int index)
row
- the row dataindex
- an index
List getRows()
void removeRow(int row)
row
- the index of the row being removedvoid removeRows(int[] deletedRows)
deletedRows
- an integer array that contains indexes of the rows being deleted
|
Copyright © 2011 Citra Technologies. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |