2

我应该如何使用 1 列的集合?我努力了:

private ObservableList<EmailU> emails= FXCollections.observableList(new ArrayList<EmailU>());

public ObservableList<EmailU> emailsProperty() {
        return emails;
    }

接着

 col_email.setCellValueFactory(
        new PropertyValueFactory<Client, ObservableList<EmailU>>("emails"));
    col_email.setCellFactory(new MultilineTextFieldCellFactory());

但得到以下错误:

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*

有任何想法吗?

4

1 回答 1

2

FooProperty方法应该根据javafx.beans.property.Property返回属性。这些属性能够通知其他实体有关它们的更改,这对于绑定和 TableView 工作至关重要。在您的情况下,它将是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);
}

请注意,您需要为 TableView 的正确工作提供 getter 和 setter。

于 2012-12-26T21:16:09.097 回答