bonjour,

Voila, dans mon application je possede une vue qui est la suivante:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
public class PanelEmploye extends JPanel implements Observer {
 
	private AppliModel monModel; // Modele
 
	private AppliControleur monControler; // Controleur
 
	private String[] columnNames = { "N° Employé", "Nom", "Hebdo", "Service" };
 
	private JButton JButtonConsulterDetailEmp;
 
	private JButton JButtonAjouterEmpl;
 
	private JButton JButtonSuppEmpl;
 
	private JButton JButtonChangeAffect;
 
	private JButton JButtonChangeHebdo;
 
	private JTable listeEmploye;
 
	private Object[][] data = null;
 
	private GridBagLayout grid;
 
	private GridBagConstraints con;
 
	public PanelEmploye(AppliControleur monC, AppliModel monM) {
 
		monControler = monC; // Initialisation du controler
		monModel = monM; // Initialisation du modele
		monModel.addObserver(this);
 
		grid = new GridBagLayout();
		con = new GridBagConstraints();
		this.setLayout(grid);
		this.setSize(700, 500);
		this.setBackground(new Color(255, 255, 255));
 
		Contrainte.donnerContrainte(con, 0, 0, 2, 1, 100, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,new Insets(20, 20, 20, 20));
		JLabel titre = new JLabel("<html><u>Veuillez sélectionner un employé dans la liste, afin de pouvoir effectuer une actions:</u></html>");
		titre.setFont(new java.awt.Font("Tahoma", 1, 12));
		this.add(titre, con);
		titre.setAutoscrolls(true);
 
		Contrainte.donnerContrainte(con, 1, 1, 1, 1, 0, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,new Insets(0, 30, 40, 30));
		JButtonAjouterEmpl = new JButton("Ajouter employé");
		this.add(JButtonAjouterEmpl, con);
		JButtonAjouterEmpl.addActionListener(monControler);
 
		Contrainte.donnerContrainte(con, 1, 2, 1, 1, 0, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,new Insets(0, 30, 40, 30));
		JButtonConsulterDetailEmp = new JButton("Voir détails employé");
		this.add(JButtonConsulterDetailEmp, con);
 
		Contrainte.donnerContrainte(con, 1, 3, 1, 1, 0, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(0, 30, 40, 30));
		JButtonSuppEmpl = new JButton("Supprimer employé");
		this.add(JButtonSuppEmpl, con);
		JButtonSuppEmpl.addActionListener(monControler);
 
		Contrainte.donnerContrainte(con, 1, 4, 1, 1, 0, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(0, 30, 40, 30));
		JButtonChangeAffect = new JButton("Changer d'affectation");
		this.add(JButtonChangeAffect, con);
		JButtonChangeAffect.addActionListener(monControler);
 
		Contrainte.donnerContrainte(con, 1, 5, 1, 1, 0, 0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(0, 30, 40, 30));
		JButtonChangeHebdo = new JButton("Changer Hebdo");
		this.add(JButtonChangeHebdo, con);
 
	}
 
	public void update(Observable o, Object arg) {
 
		if (arg.equals("employe")) {
			System.out.println("employe");
		data = monModel.getListeEmploye();
		Contrainte.donnerContrainte(con, 0, 1, 1, 5, 0, 100,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,new Insets(0, 20, 30, 0));
		listeEmploye = new JTable(data, columnNames);
		listeEmploye.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listeEmploye.setPreferredScrollableViewportSize(new Dimension(420, 300));
		JScrollPane scrollPane = new JScrollPane(listeEmploye);
		this.add(scrollPane, con);
		listeEmploye.addMouseListener(monControler);
		this.updateUI();
 
		}
 
	}
}
Lorsque je clique sur le boutton 'supprimer employer', mon controleur recupere l'index de la colonne selectionnée dans mon JTable et appel mon model qui effectue la requete dans ma base pour suprimmer l'employé.

extrait du model:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public void delEmploye(int lemploye) {
 
		try {
 
			uneSession.ouvrirConnection();
			statement = uneSession.getConnexion().prepareCall(
					"call usertest.testgestion.SUPPRIMER_UN_EMPLOYE(?)");
			statement.setInt(1, lemploye);
			statement.execute();
 
			uneSession.fermerConnection();
			rapatriListeEmploye();
 
			JOptionPane.showMessageDialog(null, "L'employé a été supprimé avec succés", "Information",
					JOptionPane.INFORMATION_MESSAGE);
 
		} catch (ErreurSQL e) {
			e.afficher();
		} catch (SQLException e) {
			try {
				throw (new ErreurSQL(e.getErrorCode(), e.getMessage()));
			} catch (ErreurSQL e1) {
				e1.afficher();
			}
		}
 
	}
a la fin de la methode delEmploye, j'appelle la methode rapatriListeEmploye() qui va rapatrier ma liste d'employé dans la base afin de mettre le tableau d'employé a jour dans mon model qui notify la vue:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
public void rapatriListeEmploye() {
 
		try {
 
			uneSession.ouvrirConnection();
			statement = uneSession.getConnexion().prepareCall(
					"call usertest.testgestion.LISTE_EMPLOYE(?,?)");
 
			statement.setInt(1, 0);
			statement.registerOutParameter(2, OracleTypes.CURSOR);
			statement.execute();
			ResultSet rst = (ResultSet) statement.getObject(2);
 
			int i = 0;
 
			while (rst.next()) {i++;}
 
			statement.execute();
			rst = (ResultSet) statement.getObject(2);
 
			listeEmploye = new Object[i][4];
 
			i = 0;
 
			while (rst.next()) {
 
				listeEmploye[i][0] = rst.getString("NUEMPL");
				listeEmploye[i][1] = rst.getString("NOMEMPL");
				listeEmploye[i][2] = rst.getString("HEBDO");
				listeEmploye[i][3] = rst.getString("NOMAFFECT");
				i++;
			}
 
			setChanged(); // Met à jour le marqueur de changement
			notifyObservers(new String("employe")); // Notifie les observers
			uneSession.fermerConnection();
 
		} catch (ErreurSQL e) {
			e.afficher();
		} catch (SQLException e) {
			try {
				throw (new ErreurSQL(e.getErrorCode(), e.getMessage()));
			} catch (ErreurSQL e1) {
				e1.afficher();
			}
		}
 
	}
 
	public Object[][] getListeEmploye() {return listeEmploye;}
Tout marche niquel mis a part que la liste ne se rafraichie pas quand je supprime un employé ou bien si j'en ajoute un...
Je ne vois pas du tout comment faire.

La supression marche, le rapatriment marche, le observer, observable marche, c'est juste la vue sui ne vue pas se rafraichir ou du mois la JTable.

J'ai essayé updateUI, repaint, rien n'y fait, des fois ca apparé, des fois ca marche mais quand je clique sur le tableau ca réapparé.

Pouvez vous m'aider??
merci