在使用按钮保存之前检查 JTable 中是否没有空行?

check if there is no an empty rows in JTable befor saving with push button?

大家好,我有一个关于检查 JTable 中的空行以告诉用户您在使用布什按钮保存数据之前忘记了一些东西的问题。我有 18 列和无限行所以我想要的是创建一个方法我可以用 ok_btn 调用还是我必须在按钮本身的动作中创建一些东西..

ok_btnActionPerformed(java.awt.event.ActionEvent evt) { 
if (not empty){
//do somthing
this.dispose();
else{
JOptionPaneShowMessageDialog(null,"you forget something!");
}

我想检查第 7 列和第 12 列!

提前致谢

我不知道你的table或table模型的结构,但你可以这样做:

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!");
}

好的,这是我更新后的代码:

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");
       }
    }