javafx.scene.control.cell

## Class PropertyValueFactory<S,T>

- java.lang.Object
- - javafx.scene.control.cell.PropertyValueFactory<S,T>

- Type Parameters:
    `S` - The type of the class contained within the TableView.items list.
    `T` - The type of the class contained within the TableColumn cells.
  All Implemented Interfaces:
    Callback<TableColumn.CellDataFeatures<S,T>,ObservableValue<T>>

      public class PropertyValueFactory<S,T>
      extends Object
      implements Callback<TableColumn.CellDataFeatures<S,T>,ObservableValue<T>>

  A convenience implementation of the Callback interface, designed specifically for use within the `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, the "firstName" string is used as a reference to an assumed `firstNameProperty()` method in the `Person` class type (which is the class type of the TableView `items` list). Additionally, this method must return a `Property` instance. If a method meeting these requirements is found, then the `TableCell` is populated with this ObservableValue. In addition, the TableView will automatically add an observer to the returned value, such that any changes fired will be observed by the TableView, resulting in the cell immediately updating.

  If no method matching this pattern exists, there is fall-through support for attempting to call get<property>() or is<property>() (that is, `getFirstName()` or `isFirstName()` in the example above). If a method matching this pattern exists, the value returned from this method is wrapped in a `ReadOnlyObjectWrapper` and returned to the TableCell. However, in this situation, this means that the TableCell will not be able to observe the ObservableValue for changes (as is the case in the first approach above).

  For reference (and as noted in the TableColumn `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();
           }
        });
       }

  Since:
    JavaFX 2.0
  See Also:
    `TableColumn`, `TableView`, `TableCell`, `TreeItemPropertyValueFactory`, `MapValueFactory`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PropertyValueFactory(String property)` Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ObservableValue<T>` | `call(TableColumn.CellDataFeatures<S,T> param)` The `call` method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.
    `String` | `getProperty()` Returns the property name provided in the constructor.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PropertyValueFactory

          public PropertyValueFactory(String property)

      Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.
      Parameters:
        `property` - The name of the property with which to attempt to reflectively extract a corresponding value for in a given object.

  - ### Method Detail

    - #### call

          public ObservableValue<T> call(TableColumn.CellDataFeatures<S,T> param)

      The `call` method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.
      Specified by:
        `call` in interface `Callback<TableColumn.CellDataFeatures<S,T>,ObservableValue<T>>`
      Parameters:
        `param` - The single argument upon which the returned value should be determined.
      Returns:
        An object of type R that may be determined based on the provided parameter value.

    - #### getProperty

          public final String getProperty()

      Returns the property name provided in the constructor.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.