0

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?

Lyly
  • 15
  • 4
  • Welcome to Stack Overflow :) Don't forget to respect [Java Naming Conventions](https://www.javatpoint.com/java-naming-conventions). All declared elements are written in CamelCase, with a lowercase letter for members and methods (`addUsers` instead of `Add_users`, `colDupl` instead of `col_dupl`). – 0009laH Oct 06 '20 at 08:17
  • I think [that request](https://stackoverflow.com/questions/7217625/how-to-add-checkboxs-to-a-tableview-in-javafx) will answer your question. – 0009laH Oct 06 '20 at 11:40
  • i think that request is about making a column of checkboxes, that's not what i am looking for, i have five 5 checkboxes and add button, whenever i click the add button, it shows on my table the text of the boxes that have been checked, the getText method though it works, it sends the text regardless of the boxes being checked, thats the issue. –  Lyly Oct 06 '20 at 13:05

0 Answers0