【问题标题】:new PropertyValueFactory<, >() for a collection集合的新 PropertyValueFactory<, >()
【发布时间】:2013-05-14 09:46:42
【问题描述】:

我的问题是我想使用 new PropertyValueFactory&lt;,&gt;() 的集合类型

TableColumn columnname = new TableColumn("Nom");
columnname.setCellValueFactory(new PropertyValueFactory<NoteBean, List>("name"));

因为我的 NoteBean 包含一个集合(List)类型的字段。

谢谢你;)。

【问题讨论】:

  • 您得到的确切错误是什么?

标签: java javafx-2 tablecolumn


【解决方案1】:

我的问题的解决方案是使用以下代码解析带有 forwhile 的集合:

    TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
 firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
     public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
         return p.getValue().firstNameProperty();
     }
  });
 }

例如:

TableColumn columnmod = new TableColumn<ModuleNoteBean, Double>(
                moBean.getModuleBean());
        for (int i = 0; i < moBean.getListmat().size(); i++) {
            TableColumn columnNote = new TableColumn(moBean.getList_mat()
                    .get(i));
            final int index = i;
            columnNote
                    .setCellValueFactory(new Callback<CellDataFeatures<ModuleNoteBean, String>, ObservableValue<String>>() {

                        public ObservableValue<String> call(
                                CellDataFeatures<ModuleNoteBean, String> p) {

                            SimpleStringProperty b = new SimpleStringProperty(p
                                    .getValue().getModuleNList().get(0)
                                    .getNoteList().get(index)
                                    + "");

                            return b;
                        }
                    });

PropertyValueFactory

【讨论】:

    猜你喜欢
    • 2014-08-29
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2013-04-28
    相关资源
    最近更新 更多