I am trying to make an attendance program in Java Swing and I try to count the number of Boolean values in every column of the first table as the number of days attended except for the 0 column index (since it contained the string values for the names) in a button click . I try to get the count of the Boolean values using a nested loop. Now when I try to use setValueAt to the cells of the other table which shows the number of days absent and present, it doesn't seem to work. Am I missing something here?
int mainTRow = mainTable.getRowCount();
int mainTCol = mainTable.getColumnCount();
JButton totBTN = new JButton("Total");
totBTN.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultTableModel mdl1 = (DefaultTableModel)showTable.getModel();
int numT=0, numF=0;
for (int i1=0; i1<mainTRow; i1++) {
for (int y=0; y<mainTCol; y++) {
Boolean obj = GetData(mainTable, i1, y+1);
if (obj == true) {
numT++;
}
else {
numF++;
}
mdl1.setValueAt(numT, i1, 1);
mdl1.setValueAt(numF, i1, 2);
}
}
}
});
Also, here is the method of the GetData used.
public Boolean GetData(JTable mainTable, int row_index, int col_index){
return (Boolean) mainTable.getModel().getValueAt(row_index, col_index);
}
This is basically a rehash of the example provided in your last question, How to copy row cell values from a JTable and transfer to another JTable, so I'm not going to go into any details.
As I said in the previous answer, if the structures of the two tables are different, you will need to convert the data between them.
If you still can't get it to work, you will need to provide a Minimal, Reproducible Example, just like I have now done, twice.