Reputation: 437
hi guys i have a question about checking for empty rows in JTable to tell user that you forget something before saving data with bush button.. i have 18 columns and unlimited rows so what i want is to creat a method that can i call with ok_btn or i have to creat somthing inside action of button itself..
ok_btnActionPerformed(java.awt.event.ActionEvent evt) {
if (not empty){
//do somthing
this.dispose();
else{
JOptionPaneShowMessageDialog(null,"you forget something!");
}
i want to check for column 7 & 12!
thanks in advance
Upvotes: 1
Views: 962
Reputation: 437
OK here is my code after i updated it:
private void btn_OkActionPerformed(java.awt.event.ActionEvent evt) {
boolean isEmpty7 = false;boolean isEmpty12 = false;
for (int i = 0; i < table.getRowCount(); i++) { //for column 7
if (table.getValueAt(i, 7).toString().equals("0.0")) {
isEmpty7 = true;
break;
}
}
for (int i = 0; i < table.getRowCount(); i++) {
if (table.getValueAt(i, 12)==null) {
isEmpty12 = true;
break;
}
}
if (!isEmpty7&&!isEmpty12){
//do somthing
this.dispose();
}else if (isEmpty7&&isEmpty12){
JOptionPane.showMessageDialog(null,"you forget something");
}else if(isEmpty7){
JOptionPane.showMessageDialog(null,"you forget row 7");
}else if (isEmpty12){
JOptionPane.showMessageDialog(null,"you forget row 12");
}
}
Upvotes: 1
Reputation: 773
I dont know structure of your table or tablemodel, but you can do it in this way:
ok_btnActionPerformed(java.awt.event.ActionEvent evt) {
boolean isEmpty = false;
for (int i = 0; i < jTable1.getRowCount(); i++) { //for column 7
if (jTable1.getValueAt(i, 7).toString().equals("")) {
isEmpty = true;
break;
}
}
if (!notEmpty){
//do somthing
this.dispose();
else{
JOptionPaneShowMessageDialog(null,"you forget something!");
}
Upvotes: 2