假设我有这样一种情况:我有一个名为
这是 AuthorProps POJO,它被
假设我有两个
我可以将名称
附言:如果需要,我可以提供工作示例。
tableAuthors
的表格视图 (TableView
),其中包含两个列 (TableColumns
) (Id 和 Name)。这是 AuthorProps POJO,它被
TableView
使用: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);
}
}
假设我有两个
TextFields
(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());
});
我可以将名称
TableColumn
绑定到txtName TextField
,因为authorsNameProperty
是一个SimpleStringProperty
,但是我无法将Id TableColumn
绑定到txtId TextField
,因为authorsIdProperty
是一个SimpleIntegerProperty
。我的问题是:如何将txtId绑定到Id TableColumn
?附言:如果需要,我可以提供工作示例。
txtId.textProperty().bind(authorProps2.authorsIdProperty().asString())
。 - James_DBindings.createIntegerBinding(...)
。 - James_D