aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes deleting row from jTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "deleting row from jTable" Watch "deleting row from jTable" New topic
Author

deleting row from jTable

nadia ghezaiel
Ranch Hand

Joined: Apr 13, 2013
Posts: 40
Hello,
Please i need help!!!

I write this code and it run correctly but without deletting any row from jTable!!!I will be crazy!!!

the code is :

JTable tableau;
public void supprimerCompte(JTable tableau){

try {

int lign= tableau.getSelectedRow();

Statement stmt = C.createStatement();

stmt.executeUpdate("DELETE FROM Compte WHERE Indice ="+lign);
System.out.println("voila c'est fait");
tableau.removeRowSelectionInterval(lign, lign);
tableau.revalidate();
}
catch (SQLException ex) {

System.out.println("Erreur de suppression du compte.");
ex.printStackTrace();
JOptionPane.showMessageDialog(null,ex.getMessage());
}


}

And :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
ConnPorCreationCompte C = new ConnPorCreationCompte();

C.supprimerCompte(jTable2);
jTable2.revalidate();


repaint();
}

After runnig I foud this result: "voila c'est fait"

Please I don't know were is the pb!!!
Please i need help,Please


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

I don't see any code that removes anything from the JTable. You remove the record from the database, then call tableau.removeRowSelectionInterval(lign, lign); which only de-selects the row. It doesn't remove anything.

To remove a row from a JTable you should use a TableModel that supports removal (like DefaultTableModel) and remove the row from it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deleting row from jTable