j'ai un problème dans le résultat et j'arrive pas à comprendre.
j'ai une jTable (jTable0) , lorsque je sélectionne une ligne et je clique sur le bouton, 2 jPanel(jPanel1 et jPanel2) s'affichent, chaque jPanel contient une jtable(jTable1 et jTable3).

Dans la première sélection tout va bien, mais après la deuxième, lorsque je clique sur le jtable1 ou jtable3 du panel 2 ou 3, les jTable se rafraichirent et affichent la résultat du premier sélection.

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
 
import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
import org.dyno.visual.swing.layouts.Trailing;
 
 
//VS4E -- DO NOT REMOVE THIS LINE!
public class Affiche extends JFrame {
 
	private static final long serialVersionUID = 1L;
	private JPanel jPanel0;
	private JTable jTable0;
	private JScrollPane jScrollPane0;
	private JTextField jTextField0;
	private JButton jButton0;
	private JScrollPane jScrollPane1;
	private JTable jTable3;
	private JScrollPane jScrollPane3;
	private JPanel jPanel2;
	private JPanel jPanel1;
	private JTable jTable1;
	private JScrollPane jScrollPane2;
	private JTable jTable2;
	private JScrollPane jScrollPane4;
	DefaultTableModel model0;
	DefaultTableModel model1;
	DefaultTableModel model2;
	DefaultTableModel model3;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public Affiche() {
		initComponents();
	}
 
	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJPanel0(), new Constraints(new Bilateral(0, 0, 0), new Bilateral(0, 0, 0)));
		setSize(875, 600);
	}
 
 
 
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			//jPanel1.setVisible(false);
			jPanel1.setBackground(Color.white);
			jPanel1.setLayout(new GroupLayout());
		}
		return jPanel1;
	}
 
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setVisible(false);
			jPanel2.setBackground(new Color(230, 230, 230));
			jPanel2.setLayout(new GroupLayout());
 
		}
		return jPanel2;
	}
 
 
	private JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setIcon(new ImageIcon(getClass().getResource("/table-multiple-icone-4353-16.png")));
			jButton0.addActionListener(new ActionListener() {
 
				public void actionPerformed(ActionEvent event) {
					jButton0ActionActionPerformed(event);
				}
			});
 
		}
		return jButton0;
	}
 
	private JScrollPane getJScrollPane0() {
		if (jScrollPane0 == null) {
			jScrollPane0 = new JScrollPane();
			jScrollPane0.setViewportView(getJTable0());
		}
		return jScrollPane0;
	}
 
	private JTable getJTable0() {
		if (jTable0 == null) {
 
 
		try
		{
 
 
	    	Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/salmen","root","");
 
        	Statement stmt = connection.createStatement();
		 	String queryString = "Select * FROM fait";
			ResultSet rs = stmt.executeQuery(queryString);
 
		 Vector<String> titreColonnes = new Vector<String>();
 
		 titreColonnes.add("id ");
		 titreColonnes.add("nom");
		 titreColonnes.add("description ");
		 titreColonnes.add("tel ");
		 Vector<Object> matrice=new Vector<Object>();
 
		 while (rs.next()) {
		 	Vector<Object> v=new Vector<Object>();
		 	v.add(rs.getInt(1));
		 	v.add(rs.getString(2));
		 	v.add(rs.getString(3));
		 	v.add(rs.getString(4));
		 	matrice.add(v);
		 	}
 
 
			model0 = new DefaultTableModel(matrice,  titreColonnes);
 
 
		jTable0 = new JTable(model0);
 
 
		//cacher la colonne id
		jTable0.getColumnModel().getColumn(0).setWidth(0);
		jTable0.getColumnModel().getColumn(0).setPreferredWidth(0);
		jTable0.getColumnModel().getColumn(0).setMinWidth(0);
		jTable0.getColumnModel().getColumn(0).setMaxWidth(0);
 
	}
 
	catch(SQLException sqle)
		{
 
		JOptionPane.showMessageDialog(null,"Connection Echouée . Contactez l'administrateur ! ","Erreur",JOptionPane.ERROR_MESSAGE);
  							 //cf Comment gérer les erreurs ? 
		}
		}
		return jTable0;
	}
 
	private JPanel getJPanel0() {
		if (jPanel0 == null) {
			jPanel0 = new JPanel();
			jPanel0.setBackground(Color.white);
			jPanel0.setBorder(new LineBorder(Color.black, 1, false));
			jPanel0.setLayout(new GroupLayout());
			jPanel0.add(getJPanel1(), new Constraints(new Leading(0, 803, 12, 12), new Leading(314, 143, 10, 10)));
			jPanel0.add(getJScrollPane0(), new Constraints(new Leading(176, 339, 10, 10), new Leading(65, 100, 10, 10)));
			jPanel0.add(getJButton0(), new Constraints(new Leading(583, 10, 10), new Leading(121, 10, 10)));
			jPanel0.add(getJPanel2(), new Constraints(new Bilateral(0, 1, 758), new Leading(174, 134, 107, 154)));
		}
		return jPanel0;
	}
 
	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}
 
	/**
         * Main entry of the class.
         * Note: This class is only created so that you can easily preview the result at runtime.
         * It is not expected to be managed by the designer.
         * You can modify it as you like.
         */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				Affiche frame = new Affiche();
				frame.setDefaultCloseOperation(Affiche.EXIT_ON_CLOSE);
				frame.setTitle("Affiche");
				frame.getContentPane().setPreferredSize(frame.getSize());
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}
 
	private void jButton0ActionActionPerformed(ActionEvent event) {
 
	try
		{
		Vector<Object> matrice1 = new Vector<Object>();
		Vector<Object> matrice2 = new Vector<Object>();
		Vector<String> titre = new Vector<String>();
		Vector<Object> v1=new Vector<Object>();	
		Vector<Object> v2=new Vector<Object>();	
 
		int ligne;
		Object c;
		String s;
		int k;
		ligne=jTable0.getSelectedRow();
		c =jTable0.getValueAt(ligne, 0);
		s = c.toString();
		k = Integer.parseInt(s);
 
		 	Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/salmen","root","");
        	Statement stmt = connection.createStatement();
 
		 	titre.add("id ");
		 	titre.add("nom");
		 	titre.add("description ");
		 	titre.add("tel ");
		 	String queryString = "Select * FROM dimension WHERE id ='"+k+"'";
			ResultSet rs = stmt.executeQuery(queryString);
 
		 	while (rs.next())
		 		 {
 
		 	v1.add(rs.getInt(1));
		 	v1.add(rs.getString(2));
		 	v1.add(rs.getString(3));
		 	v1.add(rs.getString(4));
		 	matrice1.add(v1);
		 	}
 
		model3 = new DefaultTableModel(matrice1,  titre);
		jTable3 = new JTable(model3);
		jScrollPane3 = new JScrollPane();
		jScrollPane3.setViewportView(jTable3);
		jPanel2.add(jScrollPane3, new Constraints(new Leading(180, 339, 10, 10), new Leading(20, 100, 10, 10)));
 
 
		String queryString1 = "Select * FROM meusure WHERE id ='"+k+"'";
		ResultSet rs1 = stmt.executeQuery(queryString1);
 
		 	while (rs1.next()) 
		 		{
		 	v2.add(rs1.getInt(1));
		 	v2.add(rs1.getString(2));
		 	v2.add(rs1.getString(3));
		 	v2.add(k);
		 	matrice2.add(v2);
		 	}
 
		model1 = new DefaultTableModel(matrice2,  titre);
		jTable1 = new JTable(model1);
		jScrollPane2 = new JScrollPane();
		jScrollPane2.setViewportView(jTable1);
		jPanel1.add(jScrollPane2, new Constraints(new Leading(180, 339, 10, 10), new Leading(20, 100, 10, 10)));
 
		jPanel1.setVisible(true);
		jPanel2.setVisible(true);
		jPanel1.revalidate();
		jPanel2.revalidate();		 
	}
	catch(SQLException sqle)
		{
		JOptionPane.showMessageDialog(null,"Connection Echouée . Contactez l'administrateur ! ","Erreur",JOptionPane.ERROR_MESSAGE);
		}
 
	}
}