Advertisement
aakash_goyal

cell data not rendering

Oct 2nd, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /*
  2. The resultset rs is well formed and not erroneous. We first create all columns and then add row data to and ObservableList<ObservableList> and finally set it as the data model of the tableview.
  3. */
  4.  
  5.  for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++){
  6.                    TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i+1));
  7.                    
  8.                     col.setCellValueFactory(new Callback<CellDataFeatures<TableView,Object>,Object>(){
  9.                                 public String call(CellDataFeatures<TableView,Object> param) {
  10.                                 int i = param.getIndex();
  11.                                 return ((ObservableList)param.getValue()).get(i).toString();
  12.                                 }
  13.                              });                  
  14.                 tableview.getColumns().add(col);
  15.                 }
  16.                
  17.  
  18.                 /*
  19.                  * Row data to table
  20.                  */
  21.                 while(rs.next()){
  22.                     //Iterate Row
  23.                     ObservableList<Object> row = FXCollections.observableArrayList();
  24.                     for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++){
  25.                         //Iterate Column
  26.                         row.add(rs.getString(i));
  27.                     }
  28.                     tableData.add(row);
  29.                 }
  30.                
  31.                 // Add tableData to tableView
  32.                 tableview.setItems(tableData);
  33.           }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement