|
JIDE 3.5.15 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
com.jidesoft.grid.BasicTableModel<T>
public class BasicTableModel<T>
BasicTableModel provides a quick way to create a table model from a list of objects. It leverages Introspector to introspect the object and display the value of the properties as each
column.
BasicTableModel tableModel = new BasicTableModel(objects, MyBeanObject.class);
You can also ask Introspector to create such a BasicTableModel using
new BasicTableModel(objects, IntrospectorManager.getIntrospector(MyBeanObject.class));
However to make the code above working, you need to register an Introspector first using code like below. Please
note, the string array allows you to decide what properties to be used in the BasicTableModel.
IntrospectorManager.registerIntrospector(MyBeanObject.class, new IntrospectorFactory() {
public Introspector create() {
try {
return new BeanIntrospector(MyBeanObject.class, new String[]{"name", "Name", "text", "Text", "icon",
"Icon", "opaque", "Opaque", "toolTipText", "ToolTip", "background", "Background", "foreground", "Foreground"}, 2);
}
catch (IntrospectionException e) {
return null;
}
}
});
In this example, since Introspector is an interface, we used the BeanIntrospector which will introspect the object
using Java bean pattern. If you have other ways to introspect the object, you can implement Introspector to do it.
| Field Summary | |
|---|---|
static String |
PROPERTY_EDITABLE
|
| Fields inherited from class javax.swing.table.AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
BasicTableModel()
Creates an empty BasicTableModel. |
|
BasicTableModel(List<T> objects,
Class<?> type)
Creates a BasicTableModel from a list of objects using the default BeanIntrospector for
the specified type. |
|
BasicTableModel(List<T> objects,
Class<?> type,
IntrospectorContext context)
Creates a BasicTableModel from a list of objects using the default BeanIntrospector for
the specified type and the specified BeanIntrospectorContext. |
|
BasicTableModel(List<T> objects,
Class<?> type,
String[] propertyNames)
Creates a BasicTableModel from a list of objects using the specified property names as the value for
each column of the table model. |
|
BasicTableModel(List<T> objects,
Introspector introspector)
Creates a BasicTableModel from a list of objects using the specified Introspector. |
|
| Method Summary | |
|---|---|
void |
addObject(int index,
T object)
Adds an object to the specified index of the object list. |
void |
addObject(T object)
Adds an object to the end of the object list. |
void |
addObjects(List<T> objects)
Adds objects to the table model. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. |
void |
bind(List<T> objects)
If the objects follow the JavaBean pattern, it will support property change event. |
void |
clear()
Removes all objects from the table model. |
protected void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Support for reporting property changes for boolean properties. |
void |
fireTableStructureChanged()
|
Class<?> |
getCellClassAt(int row,
int column)
Gets the type at cell (row, column). |
Class<?> |
getColumnClass(int columnIndex)
|
int |
getColumnCount()
Gets the column count. |
String |
getColumnName(int columnIndex)
|
ConverterContext |
getConverterContextAt(int rowIndex,
int columnIndex)
Gets the converter context at cell (row, column). |
EditorContext |
getEditorContextAt(int rowIndex,
int columnIndex)
Gets the editor context at cell (row, column). |
T |
getObject(int rowIndex)
Gets the object from the list of the objects. |
Property |
getPropertyAt(int columnIndex)
Gets the Property at the column index. |
int |
getRowCount()
Gets the row count. |
Object |
getValueAt(int rowIndex,
int columnIndex)
|
protected void |
installListener(T t)
|
boolean |
isCellEditable(int rowIndex,
int columnIndex)
|
boolean |
isEditable()
Get the flag indicating if the entire table model is editable. |
protected void |
prepareProperty(Property property,
int rowIndex,
int columnIndex)
This method is called in getValueAt and setValueAt method. |
void |
propertyChange(PropertyChangeEvent evt)
Updates the corresponding cell if the object's property changed. |
void |
removeObject(int index)
Removes an object from the object list at the specified index. |
void |
removeObject(T object)
Removes an object from the object list. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. |
void |
setEditable(boolean editable)
Set the flag indicating if the entire table model is editable. |
void |
setObject(T object,
int rowIndex)
Sets the object at the specified index. |
void |
setValueAt(Object value,
int rowIndex,
int columnIndex)
|
void |
unbind(List<T> objects)
Uninstalled the listeners that were installed in the bind method. |
protected void |
uninstallListener(T t)
|
| Methods inherited from class javax.swing.table.AbstractTableModel |
|---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, 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 javax.swing.table.TableModel |
|---|
addTableModelListener, removeTableModelListener |
| Field Detail |
|---|
public static final String PROPERTY_EDITABLE
| Constructor Detail |
|---|
public BasicTableModel()
BasicTableModel.
public BasicTableModel(List<T> objects,
Class<?> type)
BasicTableModel from a list of objects using the default BeanIntrospector for
the specified type. You need to register the BeanIntrospector on
BeanIntrospectorManager first.
objects - the list of objects.type - the object type
public BasicTableModel(List<T> objects,
Class<?> type,
IntrospectorContext context)
BasicTableModel from a list of objects using the default BeanIntrospector for
the specified type and the specified BeanIntrospectorContext. You need to register the
BeanIntrospector on BeanIntrospectorManager first.
objects - the list of objects.type - the object typecontext - the IntrospectorContext. We will use type and context to locate the Introspector that was
registered in IntrospectorManager.
public BasicTableModel(List<T> objects,
Class<?> type,
String[] propertyNames)
throws IntrospectionException
BasicTableModel from a list of objects using the specified property names as the value for
each column of the table model. You can also use BasicTableModel(java.util.List, Class,
com.jidesoft.introspector.IntrospectorContext) so that you can assign both name and display names using a single
array.
objects - the list of objects.type - the object typepropertyNames - an array of property names. The array is in the format of { "propertyName1",
"displayName11", "propertyName2", "displayName12", ... };
IntrospectionException - if java bean introspection failed.
public BasicTableModel(List<T> objects,
Introspector introspector)
BasicTableModel from a list of objects using the specified Introspector.
objects - the list of objects.introspector - the introspector for the object| Method Detail |
|---|
public int getRowCount()
getRowCount in interface TableModelpublic T getObject(int rowIndex)
rowIndex - the row index.
public void setObject(T object,
int rowIndex)
object - the objectrowIndex - the row indexpublic void addObject(T object)
object - the object to be added.
public void addObject(int index,
T object)
index - the index to be inserted at.object - the object to be added.public void removeObject(T object)
object - the object to be removed.public void removeObject(int index)
index - the index of the object to be removed.public void addObjects(List<T> objects)
objects - the objects to be added.public void clear()
public int getColumnCount()
getColumnCount in interface TableModelpublic Property getPropertyAt(int columnIndex)
property.setInstance(getObject(rowIndex));
columnIndex - the column index.
public Object getValueAt(int rowIndex,
int columnIndex)
getValueAt in interface TableModel
public void setValueAt(Object value,
int rowIndex,
int columnIndex)
setValueAt in interface TableModelsetValueAt in class AbstractTableModel
protected void prepareProperty(Property property,
int rowIndex,
int columnIndex)
property - the property for the cell.rowIndex - the row index of the cell where the Property is used.columnIndex - the column index of the cell where the Property is used.public String getColumnName(int columnIndex)
getColumnName in interface TableModelgetColumnName in class AbstractTableModelpublic Class<?> getColumnClass(int columnIndex)
getColumnClass in interface TableModelgetColumnClass in class AbstractTableModel
public boolean isCellEditable(int rowIndex,
int columnIndex)
isCellEditable in interface TableModelisCellEditable in class AbstractTableModel
public ConverterContext getConverterContextAt(int rowIndex,
int columnIndex)
ContextSensitiveTableModel
getConverterContextAt in interface ContextSensitiveTableModelrowIndex - the row indexcolumnIndex - the column index
public EditorContext getEditorContextAt(int rowIndex,
int columnIndex)
ContextSensitiveTableModel
getEditorContextAt in interface ContextSensitiveTableModelrowIndex - the row indexcolumnIndex - the column index
public Class<?> getCellClassAt(int row,
int column)
ContextSensitiveTableModel
getCellClassAt in interface ContextSensitiveTableModelrow - the row indexcolumn - the column index
public void bind(List<T> objects)
throws Exception
objects - the list of objects.
Exception - it fails to bind the objects.
public void unbind(List<T> objects)
throws Exception
bind method.
objects - the list of objects.
Exception - if it fails to unbind the objects.
protected void installListener(T t)
throws Exception
Exception
protected void uninstallListener(T t)
throws Exception
Exceptionpublic void propertyChange(PropertyChangeEvent evt)
propertyChange in interface PropertyChangeListenerevt - the PropertyChangeEventpublic void fireTableStructureChanged()
fireTableStructureChanged in class AbstractTableModelpublic boolean isEditable()
public void setEditable(boolean editable)
editable - the flagisEditable()
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
propertyName - the property whose value has changedoldValue - the property's previous valuenewValue - the property's new valuepublic void addPropertyChangeListener(PropertyChangeListener listener)
listener is null,
no exception is thrown and no action is performed.
listener - the property change listener to be addedremovePropertyChangeListener(java.beans.PropertyChangeListener)public void removePropertyChangeListener(PropertyChangeListener listener)
listener - the PropertyChangeListener to be removedaddPropertyChangeListener(java.beans.PropertyChangeListener)
|
JIDE 3.5.15 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||