Réponse acceptée !
je vous fourni mon code import javax.swing.table.AbstractTableModel;
public class Model_Personne extends AbstractTableModel { private Object[][] donnees; private final String[] titres; public Model_Personne(Object donnees[][], String titres[]) { this.donnees = donnees; this.titres = titres; } public int getColumnCount() { return donnees[0].length; } public Object getValueAt(int parm1, int parm2) { return donnees[parm1][parm2]; } public int getRowCount() { return donnees.length; } public String getColumnName(int col){ return titres[col]; } public boolean isCellEditable(int row, int col) { return false; } // public void delete_Row(int x) { fireTableDataChanged(); } } // import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Vector;
import javax.swing.*;
public class Frame implements ActionListener {
private JFrame f; private JPanel p; private JButton A; private JTable table; private JScrollPane scrollpane; private Vector<personne> VP; private Object[][] mesResultats; private String [] columns = {"Nom", "Prenom", "Age"}; private Model_Personne M;
public Frame () { f=new JFrame(); p=new JPanel(); A=new JButton("Supprimer"); A.addActionListener(this); // personne P1= new personne("Fabbien","Pierre",23); personne P2= new personne("XXX","AAAe",23); personne P3= new personne("AAAA","EEEE",23); VP=new Vector(); VP.add(P1); VP.add(P2); VP.add(P3); personne tmp; mesResultats = new Object[VP.size()][columns.length]; for (int i = 0 ; i < VP.size() ; i++) { tmp = VP.get(i); mesResultats[i][0] = tmp.getnom(); mesResultats[i][1] = tmp.getprenom(); mesResultats[i][2] = tmp.getage(); } M=new Model_Personne(mesResultats,columns); table = new JTable(M); table.setPreferredScrollableViewportSize(new Dimension(200, 200)); scrollpane= new JScrollPane(table); p.add(scrollpane); p.add(A); f.getContentPane().add(p); f.setVisible(true); } public static void main(String[] args) { // TODO Auto-generated method stub Frame instanc=new Frame(); } public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub if (arg0.getSource()==A) { int ligne_selec=table.getSelectedRow(); System.out.print("Numero ligne selectionee est "+ligne_selec); int res=JOptionPane.showConfirmDialog(null,
"Voulez vous vraiment suuprimer cette règle", "Supprimer Règle", JOptionPane.YES_NO_OPTION); if(res==JOptionPane.YES_OPTION) { if(ligne_selec!=-1) { M.delete_Row(ligne_selec); } } } } } je dois supprimer la ligne de donnes[][] mais je ne sais pas quel instruction merci
|