0 Replies Latest reply: Feb 11, 2013 3:45 AM by tanvir ahmed RSS

    I got data from database in tableview , now how to make tableview editable?

    tanvir ahmed
      //tableView codes
      try{

      data = FXCollections.observableArrayList();

      String SQL = "SELECT * from accounts";
      //ResultSet
      ResultSet rs = db.con.createStatement().executeQuery(SQL);

      /**********************************
      * TABLE COLUMN ADDED DYNAMICALLY *
      **********************************/
      for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++){
      //We are using non property style for making dynamic table
      final int j = i;

      acctCode.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(0).toString());
      }
      });

      acctName.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(1).toString());
      }
      });

      acctTypeId.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
      public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
      return new SimpleStringProperty(param.getValue().get(2).toString());
      }
      });

      tableView.getColumns();
      }

      /********************************
      * Data added to ObservableList *
      ********************************/
      while(rs.next()){
      //Iterate Row
      ObservableList<String> row = FXCollections.observableArrayList();
      for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++){
      //Iterate Column
      row.add(rs.getString(i));
      }

      data.add(row);
      }

      //FINALLY ADDED TO TableView
      tableView.setItems(data);
      tableView.getItems();

      }catch(Exception e){
      e.printStackTrace();
      System.out.println("Error on Building Data");
      }
      }