2015-04-15 38 views
0

让我先解释一下我做了什么。将列绑定到数据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); 
+0

我想出了解决方案。 – php83

回答

0

还有就是被大写 - 小写的错误与我的getter和setter方法。