JavaFX8-如何将TextField文本属性绑定到TableView整数属性

JavaFX8-如何将TextField文本属性绑定到TableView整数属性,java,javafx,javafx-8,Java,Javafx,Javafx 8,假设我有这样一种情况:我有一个TableView(tableAuthors),其中有两个TableColumns(Id和Name) 这是由TableView使用的AuthorProps POJO: import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; public class AuthorProps { private final S

假设我有这样一种情况:我有一个
TableView
(tableAuthors),其中有两个
TableColumns
(Id和Name)

这是由
TableView
使用的AuthorProps POJO:

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;


public class AuthorProps {
    private final SimpleIntegerProperty authorsId;
    private final SimpleStringProperty authorsName;


    public AuthorProps(int authorsId, String authorsName) {
        this.authorsId = new SimpleIntegerProperty(authorsId);
        this.authorsName = new SimpleStringProperty( authorsName);
    }

    public int getAuthorsId() {
        return authorsId.get();
    }

    public SimpleIntegerProperty authorsIdProperty() {
        return authorsId;
    }

    public void setAuthorsId(int authorsId) {
        this.authorsId.set(authorsId);
    }

    public String getAuthorsName() {
        return authorsName.get();
    }

    public SimpleStringProperty authorsNameProperty() {
        return authorsName;
    }

    public void setAuthorsName(String authorsName) {
        this.authorsName.set(authorsName);
    }
}
假设我有两个
文本字段
(txtId和txtName)。现在,我想将表单元格中的值绑定到
TextFields

 tableAuthors.getSelectionModel()
                .selectedItemProperty()
                .addListener((observableValue, authorProps, authorProps2) -> {
                    //This works:
                    txtName.textProperty().bindBidirectional(authorProps2.authorsNameProperty());
                    //This doesn't work:
                    txtId.textProperty().bindBidirectional(authorProps2.authorsIdProperty());
                });
我可以将Name
TableColumn
绑定到txtName
TextField
,因为
authorsNameProperty
是一个
SimpleStringProperty
,但我不能将Id
TableColumn
绑定到txtId
TextField
,因为
authorsIdProperty
是一个
SimpleIntegerProperty
。我的问题是:如何将txtId绑定到Id
TableColumn

注:如有必要,我可以提供工作示例。

尝试:

txtId.textProperty().bindBidirectional(authorProps2.authorsIdProperty(), new NumberStringConverter());

@Hendrikto尝试
txtId.textProperty().bind(authorProps2.authorIdproperty().asString())
@James\u D我想将IntegerProperty绑定到文本字段。完全相反。使用