|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
net.luniks.swing.IntroTableModel
Table model that takes Java beans as rows. The properties of the beans correspond to the columns of the table, their respective values are rendered depending on their type and can be set by editing the cells. For each property there has to be a public getter and setter method, the field itself is optional.
| Field Summary | |
private static java.lang.Object[] |
ARGS
|
static int |
ASCENDING
|
private java.lang.String[] |
columnNames
|
static int |
DESCENDING
|
private boolean[] |
editable
|
private static java.lang.String |
GET
|
private java.lang.reflect.Method[] |
getters
|
private static java.lang.Class[] |
PARAM_TYPES
|
private java.lang.String[] |
properties
|
private java.lang.Object[] |
rows
|
private static java.lang.String |
SET
|
private java.lang.reflect.Method[] |
setters
|
private javax.swing.JTable |
table
|
static int |
UNCHANGED
|
| Fields inherited from class javax.swing.table.AbstractTableModel |
listenerList |
| Constructor Summary | |
IntroTableModel(java.lang.Object[] rows,
java.lang.String[] properties,
java.lang.String[] columnNames,
boolean[] editable)
Constructs the table model. |
|
| Method Summary | |
int |
addRow(java.lang.Object object)
Adds the object given as argument as last row to the table. |
void |
deleteRow(int row)
Deletes the row at the index given as argument and calls fireTableRowsDeleted with the index
of the deleted row as both arguments.
|
java.lang.Class |
getColumnClass(int col)
Returns the type of the column at the index given as argument. |
int |
getColumnCount()
Returns the number of columns |
java.lang.String |
getColumnName(int col)
Returns the name of the column with the index given as argument |
java.lang.Object |
getObjectAt(int row)
Returns the bean at the row index given as argument |
int |
getRowCount()
Returns the number of rows |
java.lang.Object[] |
getRows()
Returns all rows/beans of the table |
java.lang.Object |
getValueAt(int row,
int col)
Returns the value at the row and column index given as first and second argument. |
boolean |
isCellEditable(int row,
int col)
Returns true if the column index given as second argument is editable (row is ignored), false otherwise. |
void |
moveRowToFirst(int row)
Moves the row at the index given as argument to be the first row in the table. |
void |
moveRowToLast(int row)
Moves the row at the index given as argument to be the last row in the table. |
void |
setObjectAt(java.lang.Object object,
int row)
Replaces the bean at the row index given as second argument with the bean given as first argument. |
void |
setRows(java.lang.Object[] rows)
Replaces all rows/beans with the ones given as argument and calls fireTableDataChanged |
void |
setTable(javax.swing.JTable table)
If the table this TableModel belongs to is given as argument, the table row selection is maintained when sorting using sort |
void |
setValueAt(java.lang.Object value,
int row,
int col)
Sets the value of the bean property at the row and column index given as second and third argument to the value given as first argument. |
void |
sort(int col,
int dir)
Sorts the rows by the column index given as first argument in natural order in the direction given as second argument. |
void |
swapRows(int rowA,
int rowB)
Swaps the position of the two rows given as first and second argument. |
void |
update()
This method simply calls fireTableDataChanged |
void |
update(int row)
This method simply calls fireTableRowsUpdated
with the row index given as argument as both arguments |
| 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 |
| Field Detail |
public static final int ASCENDING
public static final int DESCENDING
public static final int UNCHANGED
private static final java.lang.String GET
private static final java.lang.String SET
private static final java.lang.Object[] ARGS
private static final java.lang.Class[] PARAM_TYPES
private java.lang.Object[] rows
private java.lang.String[] properties
private java.lang.String[] columnNames
private boolean[] editable
private java.lang.reflect.Method[] getters
private java.lang.reflect.Method[] setters
private javax.swing.JTable table
| Constructor Detail |
public IntroTableModel(java.lang.Object[] rows,
java.lang.String[] properties,
java.lang.String[] columnNames,
boolean[] editable)
throws java.lang.NoSuchMethodException
rows - the beans that should be rendered in a table using this modelproperties - the names of the bean properties that should be rendered columnwisecolumnNames - the column names, number and order must match the propertieseditable - sets the columns to editable or not, number and order must match
the properties and column names| Method Detail |
public void setTable(javax.swing.JTable table)
sort
public void update()
fireTableDataChanged
public void update(int row)
fireTableRowsUpdated
with the row index given as argument as both arguments
row - the index of the row that should be updated
public void setObjectAt(java.lang.Object object,
int row)
fireTableRowsUpdated with
the row index as both arguments
object - the bean to replace the existing onerow - the row index at which to replace the beanpublic java.lang.Object getObjectAt(int row)
row - the row index of the bean to be returned
public void setRows(java.lang.Object[] rows)
fireTableDataChanged
rows - the rows to replace the existing onespublic java.lang.Object[] getRows()
public int getColumnCount()
public int getRowCount()
public java.lang.String getColumnName(int col)
col - the column index
public java.lang.Object getValueAt(int row,
int col)
row - the row indexcol - the column index
public java.lang.Class getColumnClass(int col)
getValueAt for the same column.
col - the column index
public boolean isCellEditable(int row,
int col)
row - the row index (ignored)col - the column index
public void setValueAt(java.lang.Object value,
int row,
int col)
value - the value to be set. Calls fireTableCellUpdated
with row and column index as first and second argumentrow - the row indexcol - the column index
public void swapRows(int rowA,
int rowB)
rowA - the index of one of the two rows to be swappedrowB - the index of the other of the two rows to be swappedpublic void moveRowToFirst(int row)
row - the index of the row to be moved to be the first rowpublic void moveRowToLast(int row)
row - the index of the row to be moved to be the last rowpublic int addRow(java.lang.Object object)
fireTableRowsInserted with the index of
the added row as both arguments.
object - the object to be added to the table
public void deleteRow(int row)
fireTableRowsDeleted with the index
of the deleted row as both arguments.
Does nothing if the index does not exist.
row - the index of the row to be deleted
public void sort(int col,
int dir)
throws java.lang.Exception
setTable, the row selection is maintained.
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||