我已经定义了表格:
@FXML
private TableView<FaAccount> tv_loro_nostro_accounts;
private TableColumn<FaAccount, String> tc_acc_name;
@FXML
private TableColumn<FaAccount, String> tc_currency;
然后设置setCellValueFactories(第二行的第二部分在代码中带下划线,表明存在一些错误)
tc_acc_name.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getName()));
tc_currency.setCellValueFactory(cellData -> new SimpleObjectProperty<FaCurrency>(cellData.getValue().getCurrency()));
setCellValueFactory
上的tc_currency
返回错误:bad return type in lambda expression: SimpleObjectProperty<FaCurrency> cannot be converted to ObservableValue<String>
在我的映射中,货币定义为
public class FaAccount implements Serializable {
...
@Column(name = "CurrencyID")
@Convert(converter = FaCurrencyToLongConverter.class)
private FaCurrency currency;
public FaCurrency getCurrency() {
return currency;
}
...
}
其中
FaCurrency
是enum
public enum FaCurrency {
UNKNOWN(null, "НЕИЗВЕСТНАЯ", "UNKNOWN"),
USD(1L, "ДОЛЛАР США", "USD"),
CNY(10000000001L, "КИТАЙСКИЙ ЮАНЬ", "CNY"),
GBP(90001290L, "ФУНТ СТЕРЛИНОГОВ", "GBP");
...
}
我应该在
setCellValueFactory
中使用什么,这样它才能正确编译? 最佳答案
由于要在tc_currency
列上显示的数据类型为FaCurrency
,因此需要将其定义为
private TableColumn<FaAccount, FaCurrency> tc_currency;
关于java - 在对象上使用setCellValueFactory,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31558003/