i want to make a cell that uneditable if the data that it contains equal to “VIDE”,i searched for solutions but i couldnt find any,here is the method i want to edit:
private void UpdateTables(int id) throws Exception{
DefaultTableModel model1 = (DefaultTableModel)ChosenGroupsTable.getModel();
DefaultTableModel model2 = (DefaultTableModel)NotChosenGroupsTable.getModel();
// Reset Tables
model1.setRowCount(0);
model2.setRowCount(0);
List<EnrollsVO> enrollsList = new ArrayList<>();
StudentsVO studentvo = StudentsDao.getInstance().getStudentByUserId(id);
try {
enrollsList = EnrollsDao.getInstance().loadAllStudentScreen(studentvo.getStudentID());
//System.out.println("Number of groups retrieved from the database: " + enrollsList.size());
} catch (Exception ex) {
ex.printStackTrace();
}
for(int i=0 ; i<enrollsList.size() ; i++){
EnrollsVO enroll = enrollsList.get(i);
Object[] rowData = new Object[8];
rowData[0] = enroll.getEnrollID();
rowData[1] = enroll.getCourse().getCourseName();
rowData[2] = ResponsablesDao.getInstance().getResponsableByID(enroll.getCourse().getResponsable().getResponsableID()).getFirstName();
rowData[3] = enroll.getSectionExam();
if(enroll.getCourse().getCourse_TypeID() == 2 || enroll.getCourse().getCourse_TypeID() == 4){
rowData[4] = enroll.getSectionTD();
}else{
rowData[4] = "VIDE";
// System.out.println(enroll.getCourse().getCourse_TypeID());
}
if(enroll.getCourse().getCourse_TypeID() == 2 || enroll.getCourse().getCourse_TypeID() == 4){
rowData[5] = enroll.getGroupeTD();
}else{
rowData[5] = "VIDE";
}
if(enroll.getCourse().getCourse_TypeID() == 3 || enroll.getCourse().getCourse_TypeID() == 4){
rowData[6] = enroll.getSectionTP();
}else{
rowData[6] = "VIDE";
}
if(enroll.getCourse().getCourse_TypeID() == 3 || enroll.getCourse().getCourse_TypeID() == 4){
rowData[7] = enroll.getGroupeTP();
}else{
rowData[7] = "VIDE";
}
// Check if all values from row 3 to row 7 are equal to 0
boolean allZero = true;
/*for (int j = 3; j <= 7; j++) {
if (Integer.parseInt(rowData[j].toString()) != 0) {
allZero = false;
break;
}
}
// If all values from row 3 to row 7 are equal to 0, set rowData to "VIDE"
if (allZero) {
for (int j = 3; j <= 7; j++) {
rowData[j] = "VIDE";
}
}
*/
if (enroll.getSectionExam() != 0 && enroll.getSectionTD() != 0 && enroll.getGroupeTD()!= 0 && enroll.getSectionTP() != 0 && enroll.getGroupeTP()!= 0) {
model1.addRow(rowData);
} else {
model2.addRow(rowData);
}
}
NotChosenGroupsTable.getColumnModel().getColumn(3).setCellRenderer(new GandSJInternalFrame.CustomCellRenderer());
NotChosenGroupsTable.getColumnModel().getColumn(4).setCellRenderer(new GandSJInternalFrame.CustomCellRenderer());
NotChosenGroupsTable.getColumnModel().getColumn(5).setCellRenderer(new GandSJInternalFrame.CustomCellRenderer());
NotChosenGroupsTable.getColumnModel().getColumn(6).setCellRenderer(new GandSJInternalFrame.CustomCellRenderer());
NotChosenGroupsTable.getColumnModel().getColumn(7).setCellRenderer(new GandSJInternalFrame.CustomCellRenderer());
}
i tried using isCellEditable method and overriding it,and many other solutions,i need this asap if u know the solution to it.tyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
New contributor
HowMuch4zN8t is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.