Very Good, It turns out that my program when starting recreates the JButtons based on a DB with a WHILE, and I have already programmed the part in which I can delete the person from a JTable, what happens is that in doing so the JPanel follows showing the JButton that was supposedly already deleted, Any advice?
Method with which I charge the JButtons
public void cargarBotonesInstaladores(){
try{
Connection miConexion = DriverManager.getConnection("jdbc:sqlite:instaladores3Claro.db");
Statement miStatement = miConexion.createStatement();
ResultSet miResultSet = miStatement.executeQuery("SELECT id, name, identification, color FROM instaladores3Claro");
while(miResultSet.next()){
Person p = new Person(miResultSet.getString("name"),
miResultSet.getString("identification"));
PersonAction pa = new PersonAction(p);
JButton jb = new JButton(pa);
jb.setBackground(getColor(miResultSet.getString("color")));
pnlIns.add(jb);
pnlIns.revalidate();
pnlIns.repaint();
}
}catch(Exception e){
System.out.println(e);
}
}
Button that performs the delete method:
private void eliminarInsActionPerformed(java.awt.event.ActionEvent evt) {
int filasel;
String id;
try
{
filasel = tblInstaladores.getSelectedRow();
if(filasel == -1)
{
JOptionPane.showMessageDialog(null, "No se ha seleccionado ninguna fila a eliminar");
}
else
{
modeloIns = (DefaultTableModel) tblInstaladores.getModel();
id = (String) modeloIns.getValueAt(filasel, 0);
EliminarIns(id);
}
pnlIns.revalidate();
pnlIns.repaint();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
Method that eliminates:
void EliminarIns(String id){
try{
Connection miConexionInstaladores = DriverManager.getConnection("jdbc:sqlite:instaladores3Claro.db");
PreparedStatement pst = miConexionInstaladores.prepareStatement("DELETE FROM instaladores3Claro "+
"WHERE id = "+id);
Statement miStatementIns = miConexionInstaladores.createStatement();
int m = pst.executeUpdate();
if(m > 0){
CargarTablaInstaladores("");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
I hope you can help me:)