I have a problem removing a java record in a jtable

0

When selecting a reg in a column with a checkbox, the whole row of blue is marked and when the row of blue is marked, it can not be deleted because it does not recognize the Boolean value of the checkbox and as it does not recognize it, it can not be eliminated this is the image

this is the code to eliminate public void leeRifIdentif(){ String RIF; int cont=0; TableModel model = datalistado.getModel(); for(int i = 0; i < model.getRowCount(); i++){ if((Boolean)model.getValueAt(i, 0) == true){ RIF=((String)model.getValueAt(i, 1)); cont++; try{ ps =cn.prepareStatement("DELETE FROM cliente WHERE rif=?"); String rif = String.valueOf(RIF); ps.setString(1,rif); ps.executeUpdate(); MostrarDatos(false); VaciarCampos();
}catch(Exception e){ System.out.println(e.getMessage()); } }
} if(cont == model.getRowCount()){ CboCampo.setSelected(false); } }
when evaluating the condition to know if it is true as it is marked the row I take it false

    
asked by Efrainrodc 26.12.2016 в 22:07
source

1 answer

1

I do not have all the complete code to help you. But this should delete only the selected.

In the code that you present is inside a for. Something like that is going to serve you. Add within your method leeRifIdentif

....
   DefaultTableModel model = (DefaultTableModel) this.table.getModel();
   int[] rows = table.getSelectedRows();
   for(int i = 0; i < rows.length; i++){
     // Aca borras de tu model.
     model.removeRow(rows[i]-i);

     // Borras de tu base de datos.
   }
}

Since I do not have all the code, I do not know where you are calling from your leeRifIdentif. I assume that from an event when selecting your records

    
answered by 27.12.2016 / 02:41
source