JavaFX Property Display in Controls

I am working on Oracle JavaFX tutorials. After doing Swing for many years (a long time ago), I am fascinated by new smart features, including. properties. I was surprised to see that these examples (for example: https://docs.oracle.com/javafx/2/ui_controls/table-view.htm ) do not use them the way I think is "correct."

The example creates a class Personwith properties as fields:

public static class Person {
    private final SimpleStringProperty firstName;
    ...

But the recipients are not for properties, but for their values

    public String getFirstName() {
        return firstName.get();
    }

therefore, when he associates them with TableCellin columns, he transfers them to a new property:

    emailCol.setCellValueFactory(
            new PropertyValueFactory<Person, String>("firstName"));

This seems confusing to me and misses the real advantage of event propagation by not just using it:

    firstNameCol.setCellValueFactory( celldata -> 
        celldata.getValue().firstNameProperty());

: , bean ? - ?

NB: , : Person , table.refresh() .

+6
1

-, , :

public class Person {

    private final StringProperty firstName = new SimpleStringProperty();

    public StringProperty firstNameProperty() {
        return firstName ;
    }

    public final String getFirstName() {
        return firstNameProperty().get();
    }

    public final void setFirstName(String firstName) {
        firstNameProperty().set(firstName);
    }
}

table.refresh(). PropertyValueFactory, .

, , , PropertyValueFactory. , , PropertyValueFactory. -, , PropertyValueFactory String, , . , :

firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstname"));

, . ( : Javafx PropertyValueFactory, Tableview).

-, PropertyValueFactory , , -. , , .

PropertyValueFactory . Java 8, , -, factory :

firstNameCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
    @Override
    public ObservableValue<String> call(TableColumn.CellDataFeatures<Person, String> cellData) {
        return cellData.getValue().firstNameProperty();
    }
});

, JavaFX PropertyValueFactory API.

Java 8 PropertyValueFactory , . , , Java 8, - ( , JavaFX 2, " t ), , , , , . , PropertyValueFactory.

(: TL; DR: , .)

+7

All Articles