Reputation: 1772
How am I supposed to work with Collections for 1 column? I have tried:
private ObservableList<EmailU> emails= FXCollections.observableList(new ArrayList<EmailU>());
public ObservableList<EmailU> emailsProperty() {
return emails;
}
and then
col_email.setCellValueFactory(
new PropertyValueFactory<Client, ObservableList<EmailU>>("emails"));
col_email.setCellFactory(new MultilineTextFieldCellFactory());
but get the following error:
SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: TableRow[id=null, styleClass=cell indexed-cell table-row-cell], name: skinClassName, value: com.sun.javafx.scene.control.skin.TableRowSkin]' for control TableRow[id=null, styleClass=cell indexed-cell table-row-cell]
java.lang.RuntimeException: java.lang.ClassCastException: com.sun.javafx.collections.ObservableListWrapper cannot be cast to javafx.beans.property.ReadOnlyProperty*
Any ideas?
Upvotes: 2
Views: 3268
Reputation: 34528
FooProperty
method should return property in terms of javafx.beans.property.Property. These properties are capable of notifying other entities about their changes which is vital for binding and TableView work. In your case it would be ListProperty
:
private ListProperty<EmailU> emails = new SimpleListProperty<>(
FXCollections.observableList(new ArrayList<EmailU>()));
public ListProperty<EmailU> emailsProperty() {
return emails;
}
public ObservableList<EmailU> getEmails() {
return emailsProperty().get();
}
public void setEmails(ObservableList<EmailU> emails) {
emailsProperty().set(emails);
}
Note you need to provide getter and setter for correct work of TableView.
Upvotes: 2