mardi 6 octobre 2020

how to get JavaFX checkboxes data to load in Tableview on action?

can somebody help me with some checkboxes I wanna get their text loaded in their respective column in my Tableview with an Add method, here is the code of my controller class :

public class Controller implements Initializable{


@FXML
private CheckBox check_fc;

@FXML
private CheckBox check_nc;

@FXML
private CheckBox check_mspd;

@FXML
private CheckBox check_dupl;

@FXML
private CheckBox check_gps;

@FXML
private CheckBox check_pw;

@FXML
private TableView<users> table_users;

@FXML
private TableColumn<users, String> col_fc;

@FXML
private TableColumn<users, String> col_nc;

@FXML
private TableColumn<users, String> col_dupl;

@FXML
private TableColumn<users, String> col_mspd;

@FXML
private TableColumn<users, String> col_gps;

@FXML
private TableColumn<users, String> col_pw;



ObservableList<users> listM;

int index = -1;

Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;

public void Add_users() {
    
    conn = mysqlconnect.ConnectDb();
    String sql = "insert into users (fc, nc, dupl, mspd, gps, pw)Values(?,?,?,?,?,?)";
    
    try {
        
        pst = conn.prepareStatement(sql);
        pst.setString(4, check_fc.getText());
        pst.setString(5, check_nc.getText());
        pst.setString(6, check_dupl.getText());
        pst.setString(7, check_mspd.getText());
        pst.setString(8, check_gps.getText());
        pst.setString(9, check_pw.getText());
        
        
        pst.execute();
        
        JOptionPane.showMessageDialog(null, "addition was a success");

    } catch (Exception e) {
        
        JOptionPane.showMessageDialog(null, e);
        
    }
    
    
    
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    
    col_fc.setCellValueFactory(new PropertyValueFactory<users,String>("fc"));
    col_nc.setCellValueFactory(new PropertyValueFactory<users,String>("nc"));
    col_dupl.setCellValueFactory(new PropertyValueFactory<users,String>("dupl"));
    col_mspd.setCellValueFactory(new PropertyValueFactory<users,String>("mspd"));
    col_gps.setCellValueFactory(new PropertyValueFactory<users,String>("gps"));
    col_pw.setCellValueFactory(new PropertyValueFactory<users,String>("pw"));
     

    listM = mysqlconnect.getDatausers();
    table_users.setItems(listM);
}
}

the app works but I'm getting my checkboxes text all the time instead of when being checked, I am new here, I tried to find some youtube videos and look for some answers online to no avail, I couldn't specifically find what I wanted, so I came here as a last resort.




Aucun commentaire:

Enregistrer un commentaire