Louis Etienne
Louis Etienne

Reputation: 1371

Convert a String to an ObservableValue<String>

I would like to create a TableView. In my .fxml controller, I have these two columns:

@FXML
private TableColumn<Log, String> planeRegistrationColumn;
@FXML
private TableColumn<Log, String> planeTypeColumn;

The log class has an attribute Plane which is a Plane instance. But the setCellValueFactory doesn't seem to like it:

planeRegistrationColumn.setCellValueFactory(cellData -> cellData.getValue().planeProperty().get().getRegistration());

getRegistration() returns a String, but it needs an ObservableValue<String>. Is it a conception problem? And if not, how to can I do this?

Upvotes: 1

Views: 6797

Answers (1)

James_D
James_D

Reputation: 209225

Just wrap the string you get in some kind of observable value:

planeRegistrationColumn.setCellValueFactory(cellData -> 
    new SimpleStringProperty(cellData.getValue().planeProperty().get().getRegistration()));

Upvotes: 2

Related Questions