将列绑定到数据 javafx



让我先解释一下我做了什么。

  1. 我在下拉列表中有表列表
  2. 当有人选择任何一个时,它将根据列名将所有数据填充到 TableView

我能够从表中获取列并将其放在表视图中,但我无法将数据与关联的列绑定。

我在这里的代码是看

        this.tableName  =   clsComboData.getValue();
    System.out.println(tableName); System.out.println("Button Pressed");
    List<StaticColumnConfig> allColumns =   null;
    for(StaticDataTable dataTable : dropdown) {
        if(dataTable.getTableName() != null && dataTable.getTableName().equalsIgnoreCase(tableName)) {
            System.out.println(dataTable.getColumnConfig());
            allColumns  =   dataTable.getColumnConfig();
         }
    }
    switch (tableName) {
    case "IOSwapCounterparties":    SimpleDateFormat date = new SimpleDateFormat("2015-04-15");
                                    System.out.println("Into the Switch");
                                    data = FXCollections.observableArrayList(
                                        new IOSwapCounterparties(1,"a","b","c","d","e",date),
                                        new IOSwapCounterparties(1,"aa","bb","cv","dd","es",date),
                                        new IOSwapCounterparties(1,"ad","bd","cd","dc","eb",date),
                                        new IOSwapCounterparties(1,"aw","bw","cr","dt","ey",date),
                                        new IOSwapCounterparties(1,"ag","bt","cy","du","ep",date)
                                    );
             break;
    }
    //System.out.println("Its in ELSE");            
    //"Invited" column
    TableColumn checkboxCol = new TableColumn<Person, Boolean>();
    checkboxCol.setText("");
    checkboxCol.setMinWidth(50);
    checkboxCol.setCellValueFactory(new PropertyValueFactory("checkbox"));
    // Create checkboxes
    checkboxCol.setCellFactory(new Callback<TableColumn<Person, Boolean>, TableCell<Person, Boolean>>() {
        public TableCell<Person, Boolean> call(TableColumn<Person, Boolean> p) {
            CheckBoxTableCell<Person, Boolean> checkBox = new CheckBoxTableCell();              
            return checkBox;
        }
    });         
    //Set cell factory for cells that allow editing
    Callback<TableColumn, TableCell> cellFactory =
      new Callback<TableColumn, TableCell>() {
        public TableCell call(TableColumn p) {
            return new EditingCell();
        }
    };
    for(StaticColumnConfig column : allColumns){                                
        TableColumn oneColumn = new TableColumn(column.getColumnName());
        oneColumn.setCellFactory(cellFactory);
    }
    // Clear the tableview for next table
    tblViewer.getColumns().clear();     
    // Push the data to the tableview
    tblViewer.setItems(data);           
    tblViewer.setEditable(true);
    tblViewer.getColumns().addAll(checkboxCol);
    for(StaticColumnConfig column : allColumns){
        System.out.println(column.getColumnName());
        TableColumn oneColumn = new TableColumn(column.getColumnName());
        tblViewer.getColumns().addAll(oneColumn);
    }
    // Add the columns
    tblViewer.getSelectionModel().setCellSelectionEnabled(true);             
    tblViewer.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);  

我的 getter 和 setter 方法存在大写 - 小写错误。

最新更新