在对象上使用setCellValueFactory

时间:2015-07-22 08:36:01

标签: java javafx javafx-8

我已经定义了表格:

OpenCV

然后设置setCellValueFactories(第二行的第二部分在代码中加下划线,表明存在一些错误)

    @FXML
    private TableView<FaAccount> tv_loro_nostro_accounts;
    private TableColumn<FaAccount, String> tc_acc_name;
    @FXML
    private TableColumn<FaAccount, String> tc_currency;
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"); ... } 中使用什么,以便编译时没有错误?

1 个答案:

答案 0 :(得分:2)

由于您要在tc_currency列上显示的数据类型为FaCurrency,因此您需要将其定义为

private TableColumn<FaAccount, FaCurrency> tc_currency;