|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
com.sciapp.table.ObjectTableModel
public abstract class ObjectTableModel
ObjectTableModel uses an internal ArrayList structure to store the rows of a JTable.
The elements in the list can be any Java object.
Subclasses should implement getValueAt(int, int)
and setValueAt(java.lang.Object, int, int)
, which define
how objects at a column index are retrieved/set respectively.
The column names are specified in the constructor, or with setColumns(java.lang.String[])
Field Summary | |
---|---|
protected String[] |
columns
A String array holding the columns of the TableModel |
protected ArrayList |
rows
The actual table rows stored in an ArrayList. |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
ObjectTableModel(String[] columns)
Constructs an ObjectTableModel with columns as the table columns. |
Method Summary | |
---|---|
void |
addRow(Object o)
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. |
Object |
getCellValue(Object o,
int index)
Returns the Object found at index of row passed as a parameter. |
Class |
getColumnClass(int c)
Returns the class of the object at column c. |
int |
getColumnCount()
Returns the number of columns in the model. |
String |
getColumnName(int column)
Returns the name of the column at column , which depends
on the String array passed in the constructor. |
String[] |
getColumns()
Returns a clone of the String array of table column names. |
int |
getRowCount()
Returns the number of rows in the model. |
List |
getRows()
Returns the data of this tablemodel |
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value for the cell at columnIndex and
rowIndex . |
abstract Object |
getValueAt(Object o,
int index)
Returns the value for the object o at index. |
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns true by default. |
void |
removeRow(int row)
Removes a row from the data model |
void |
removeRows(int[] deletedRows)
Removes a few rows from the data model |
void |
setColumns(String[] columns)
Sets the table columns. |
void |
setValueAt(Object aValue,
int rowIndex,
int columnIndex)
Assigns aValue to the object at columnIndex and rowIndex . |
abstract void |
setValueAt(Object o,
Object aValue,
int index)
Sets the value of Object o at index to aValue |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.sciapp.table.ListTableModel |
---|
fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, removeTableModelListener |
Field Detail |
---|
protected ArrayList rows
protected String[] columns
Constructor Detail |
---|
public ObjectTableModel(String[] columns)
columns
as the table columns.
Method Detail |
---|
public void addRow(Object o)
addRow
in interface ListTableModel
o
- the row being addedpublic void addRows(List addedRows)
addedRows contains objects representing the actual rows being added. e.g. java.util.Vector, for DefaultTableModel.
addRows
in interface ListTableModel
addedRows
- the rows being added.public void clear()
clear
in interface ListTableModel
public Object getCellValue(Object o, int index)
getCellValue
in interface ListTableModel
o
- the row dataindex
- an index
public Class getColumnClass(int c)
getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
c
- the column
public int getColumnCount()
JTable
uses this method to determine how many columns it
should create and display by default.
getColumnCount
in interface TableModel
TableModel.getRowCount()
public String getColumnName(int column)
column
, which depends
on the String array passed in the constructor.
getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
column
- the column being queried
column
.public String[] getColumns()
public int getRowCount()
JTable
uses this method to determine how many rows it
should display. This method should be quick, as it
is called frequently during rendering.
getRowCount
in interface TableModel
TableModel.getColumnCount()
public List getRows()
getRows
in interface ListTableModel
public Object getValueAt(int rowIndex, int columnIndex)
columnIndex
and
rowIndex
.
getValueAt
in interface TableModel
rowIndex
- the row whose value is to be queriedcolumnIndex
- the column whose value is to be queried
public abstract Object getValueAt(Object o, int index)
o
- the object whose value is to be queriedindex
- the column whose value is to be queried
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
rowIndex
- the row being queriedcolumnIndex
- the column being queried
TableModel.setValueAt(java.lang.Object, int, int)
public void removeRow(int row)
removeRow
in interface ListTableModel
row
- the index of the row being removedpublic void removeRows(int[] deletedRows)
removeRows
in interface ListTableModel
deletedRows
- an integer array that contains indexes of the rows being deletedpublic void setColumns(String[] columns)
columns
- the table columns as an array of Stringspublic void setValueAt(Object aValue, int rowIndex, int columnIndex)
aValue
to the object at columnIndex
and rowIndex
.
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
aValue
- value to assign to the cellrowIndex
- row of the cellcolumnIndex
- column of the cellTableModel.getValueAt(int, int)
,
TableModel.isCellEditable(int, int)
public abstract void setValueAt(Object o, Object aValue, int index)
o
- the object whose value is to be changedaValue
- the new valueindex
- the index whose value is to be changed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |