TableColumn
cell value factory. An example
of how to use this class is:
TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
firstNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("firstName"));
In this example, Person is the class type of the TableView
items list.
The class Person must be declared public.
PropertyValueFactory uses the constructor argument,
"firstName", to assume that Person has a public method
firstNameProperty with no formal parameters and a return type of
ObservableValue<String>.
If such a method exists, then it is invoked, and additionally assumed
to return an instance of Property<String>. The return value is used
to populate the TableCell. In addition, the TableView adds
an observer to the return value, such that any changes fired will be observed
by the TableView, resulting in the cell immediately updating.
If no such method exists, then PropertyValueFactory
assumes that Person has a public method getFirstName or
isFirstName with no formal parameters and a return type of
String. If such a method exists, then it is invoked, and its return
value is wrapped in a ReadOnlyObjectWrapper
and returned to the TableCell. In this situation,
the TableCell will not be able to observe changes to the property,
unlike in the first approach above.
For reference (and as noted in the TableColumn
TableColumn#cellValueFactoryProperty() cell value factory} documentation), the
long form of the code above would be the following:
TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
// p.getValue() returns the Person instance for a particular TableView row
return p.getValue().firstNameProperty();
}
});
}
Deploying an Application as a Module
If the referenced class is in a named module, then it must be reflectively
accessible to the javafx.base module.
A class is reflectively accessible if the module
opens the containing package to at
least the javafx.base module.
Otherwise the call(TableColumn. method
will log a warning and return null.
For example, if the Person class is in the com.foo package
in the foo.app module, the module-info.java might
look like this:
module foo.app {
opens com.foo to javafx.base;
}
Alternatively, a class is reflectively accessible if the module
exports the containing package
unconditionally.
TableColumn, TableView, TableCell, TreeItemPropertyValueFactory, MapValueFactory
| Modifier and Type | Field and Description |
|---|---|
| private Class | |
| private String | |
| private final String | |
| private PropertyReference |
| Access | Constructor and Description |
|---|---|
| public | PropertyValueFactory(String
The name of the property with which to attempt to
reflectively extract a corresponding value for in a given object. property)Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name. |
| Modifier and Type | Method and Description |
|---|---|
| public ObservableValue | call(TableColumn.
Implements javafx. The |
| private ObservableValue | |
| public final String | Returns: the property name provided in the constructorReturns the property name provided in the constructor. |
| columnClass | back to summary |
|---|---|
| private Class<?> columnClass | |
| previousProperty | back to summary |
|---|---|
| private String previousProperty | |
| property | back to summary |
|---|---|
| private final String property | |
| propertyRef | back to summary |
|---|---|
| private PropertyReference<T> propertyRef | |
| PropertyValueFactory | back to summary |
|---|---|
| public PropertyValueFactory(String property) Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.
| |
| call | back to summary |
|---|---|
| public ObservableValue Implements javafx. Doc from javafx. The
| |
| getCellDataReflectively | back to summary |
|---|---|
| private ObservableValue | |
| getProperty | back to summary |
|---|---|
| public final String getProperty() Returns the property name provided in the constructor.
| |