我有这个配置的TableView:
@FXML
private TableView<Budget> budgetTable;
@FXML
private TableColumn<Budget, String> idColumn, budgetNameColumn, buildingColumn, addressColumn, taxableColumn,
budgetTotalColumn, budgetStateColumn, clientColumn;
@FXML
private TableColumn<Budget, LocalDate> budgetDateColumn;
@FXML
private void initialize() {
...
clientColumn.setCellValueFactory(new Callback<CellDataFeatures<Budget, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<Budget, String> data) {
if (data.getValue().getClient() != null) {
return data.getValue().getClient().nameProperty().concat(" ")
.concat(data.getValue().getClient().surnameProperty());
}
return null;
}
});
...
}
答案 0 :(得分:0)
对于null
案例,请返回空StringProperty
。
clientColumn.setCellValueFactory(new Callback<CellDataFeatures<Budget, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<Budget, String> data) {
if (data.getValue().getClient() != null) {
return data.getValue().getClient().nameProperty().concat(" ")
.concat(data.getValue().getClient().surnameProperty());
}
return new ReadOnlyStringWrapper("");
}
});
答案 1 :(得分:0)
我找到了一个&#34;解决方案&#34;工作。我不知道为什么它会像那样工作,但此时它的工作原理如下:
clientColumn.setCellValueFactory(new Callback<CellDataFeatures<Budget, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<Budget, String> data) {
if (data.getValue().getClient() != null) {
return data.getValue().getClient().nameProperty().concat(" ")
.concat(data.getValue().getClient().surnameProperty());
} else {
budgetList.remove(data.getValue());
}
return new ReadOnlyStringWrapper("");
}
});
我只是从observableList中删除了null元素:)