Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/04/2016, 15:36
fran7751
 
Fecha de Ingreso: abril-2016
Mensajes: 16
Antigüedad: 8 años
Puntos: 0
Exclamación Eliminar una fila en JTable mediante Checkbox

Hola chicos, buenas tardes, estoy con un pequeño problema, resulta que deseo seleccionar una fila o varias filas para eliminar mediante un checkbox, creo un checkbox y lo inserto en mi Jtable, pero me da error, que es lo que hago mal?Gracias!!

Declaro el chekbox:

JCheckBox checkBoxJtable;

Cargo datos y JCheckBox en la Jtable:

String posicion = null;
int total = 0;
DefaultTableModel modeloDeMiTabla=(DefaultTableModel)table.getModel( );
modeloDeMiTabla.addRow(new Object[numeroFilas]);

table.setValueAt(checkBoxJtable, numeroFilas, 0); ////Insertamos el check box!
table.setValueAt(textField_NombreBebidas.getText() , numeroFilas, 1);
table.setValueAt("13:00", numeroFilas, 2);
table.setValueAt(textField_PrecioBebidas.getText() , numeroFilas, 3);

int fila = table.getRowCount();
int i;


for (i = 0; i < fila; i++) {
posicion = (String) table.getValueAt(i, 3);

int valor = Integer.parseInt(posicion);

total= total+valor;

}

String totalFinal = String.valueOf(total);


textField_Total.setText(totalFinal);

numeroFilas++;

bebidas.setNombreBebida(textField_NombreBebidas.ge tText());
bebidas.setPrecioBebida(Integer.valueOf(textField_ PrecioBebidas.getText()));

bebidasarraylist.add(bebidas);

}


ELIMINAR:

btnEliminar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

if( checkBoxJtable.isSelected()){

try {

DefaultTableModel modeloDeMiTabla=(DefaultTableModel)table.getModel( );
modeloDeMiTabla.removeRow(table.getSelectedRow());
table.addRowSelectionInterval(0,0);
modeloDeMiTabla=null;

} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Seleccione la fila que desea quitar.");
}


}else{

System.out.println("NO encuentro la opcion");

}

}
});

btnEliminar.setBounds(142, 584, 117, 25);
panel.add(btnEliminar);



al realizar eso me da el siguiente error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException <-----