如何处理JTable的整数列中的空字段?

How to process empty fields in integer column of JTable?

我在 table 中有一列包含数值。但是,有些字段是空的。我想将此列中的所有字段读入整数变量。我应该如何管理空白字段?

int total = tableModel.getValueAt(currentRow, currentCol).toString().equals("") ? 0 : Integer.parseInt(tablePaxModel.getValueAt(currentRow, currentCol).toString());
something like

try {
    String val = tablePaxModel.getValueAt(currentRow, currentCol).toString();

    int temp=0;
    if(val.isEmpty() || val == null)
       temp=0;

    else
    {
    temp = Integer.parseInt(val);
    }

    total = total + temp
}

catch (Exception e) 
    {
        e.printStackTrace();  
    }

类似的东西。我对您的代码做了一些假设,但您可以根据需要进行修改

     try 
     {
        String valueInCell = (String)tablePaxModel.getValueAt(currentRow, currentCol);

        if(valueInCell == null || valueInCell.isEmpty())
        {
            valueInCell = "0";
        }

        int tempCellValue = Integer.parseInt(valueInCell);

        total += tempCellValue;

    } catch (Exception e) 
    {
        e.printStackTrace();  
    }