在对象上使用 setCellValueFactory
Using setCellValueFactory on objects
我定义了table:
@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
returns 错误:
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;
我定义了table:
@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
returns 错误:
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;