I wanna make a TableView
where each column contains a checkbox with a specified text, with an Add
method. Here is the code of my controller class :
public class Controller implements Initializable {
@FXML
private CheckBox checkFc, checkNc,
checkMspd, checkDupl,
checkGps, checkPw;
@FXML
private TableView<users> tableUsers;
@FXML
private TableColumn<users, String> colFc, colNc,
colDupl, colMspd,
colGps, colPw;
ObservableList<users> listM;
int index = -1;
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
public void AddUsers() {
conn = mysqlconnect.ConnectDb();
String sql = "insert into users (fc, nc, dupl, mspd, gps, pw)Values(?,?,?,?,?,?)";
try {
pst = conn.prepareStatement(sql);
pst.setString(4, checkFc.getText());
pst.setString(5, checkNc.getText());
pst.setString(6, checkDupl.getText());
pst.setString(7, checkMspd.getText());
pst.setString(8, checkGps.getText());
pst.setString(9, checkPw.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) {
colFc.setCellValueFactory(new PropertyValueFactory<users,String>("fc"));
colNc.setCellValueFactory(new PropertyValueFactory<users,String>("nc"));
colDupl.setCellValueFactory(new PropertyValueFactory<users,String>("dupl"));
colMspd.setCellValueFactory(new PropertyValueFactory<users,String>("mspd"));
colGps.setCellValueFactory(new PropertyValueFactory<users,String>("gps"));
colPw.setCellValueFactory(new PropertyValueFactory<users,String>("pw"));
listM = mysqlconnect.getDatausers();
tableUsers.setItems(listM);
}
}
The app works fine but my checkboxes text is visible all the time instead of when being checked. I unsuccessfully tried to find some YouTube videos and look for some answers online, can anybody help me?