SVP, Repondez moi avant que je
quand je click dans le combobox, la table est supposée changer de valeurs, mais ça le fait pas, de l'aide....
voici le code (j'ai retiré le code qui connect a la BD) pour vous permettre de tester sur vos pc.
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
/*
 * Created on Apr 1, 2011
 */
package day1;
 
 
import java.util.*;
import javax.swing.*;
 
 
 
import java.sql.*;
/**
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class RefreshJTable2 extends JFrame {
 
	private JPanel jContentPane = null;
	private Vector columnCombo = new Vector();
	private Vector columnNames = new Vector();
	private Vector columnData = new Vector();
	private String item = ""; 
	private Vector cl = new Vector();
 
	private JComboBox jComboBox = null;
 
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	public static void main(String[] args) {
		RefreshJTable2 rt = new RefreshJTable2();
		}
 
	/**
         * This is the default constructor
         */
	public RefreshJTable2() {
		super();
		initialize();
	//	getDataList();
 
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	/**
         * This method initializes this
         */
	private void initialize() {
		this.setSize(452, 200);
		this.setContentPane(getJContentPane());
	}
	/**
         * This method initializes jContentPane
         */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new  JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJComboBox(), null);
			jContentPane.add(getJScrollPane(), null);
		}
		return jContentPane;
	}
	/**
         * This method initializes jComboBox
         */
	private JComboBox getJComboBox() {
		if(jComboBox == null) {
			jComboBox = new JComboBox();
			columnCombo.addElement("1");
			columnCombo.addElement("2");
			columnCombo.addElement("3");
			jComboBox = new JComboBox(columnCombo);
 
			jComboBox.setBounds(227, 14, 181, 26);
 
			jComboBox.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) {    
					//---- comboBox
					columnCombo.removeAllElements();
					getDataListCombo();
 
					//---- Table list
					item =  (String) jComboBox.getSelectedItem();
					getDataList();
 
					//jTable = new JTable(columnData,cl);
					repaint();
				}
			});	
		}
		return jComboBox;
	}
 
 
	public void getDataListCombo() {
			//item = (String) jComboBox.getSelectedItem();
 
			int countRows = 0;
			//System.out.println(countRows + "----" + item);
			String data = "jdbc:odbc:WorldEnergy";
			try {
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				Connection conn = DriverManager.getConnection(data, "", "");
				Statement st = conn.createStatement();
				ResultSet rec =
					st.executeQuery("SELECT DISTINCT Country FROM Coal  ORDER BY Country");
 
				while (rec.next()) {
					countRows++;
					columnCombo.addElement(rec.getObject(1));
				}
				st.close();
 
			} catch (SQLException s) {
				System.out.println("SQL Error: "+ s.toString()+ " "	+ s.getErrorCode()
						+ " "
						+ s.getSQLState());
			} catch (Exception e) {
				System.out.println("Error: " + e.toString() + e.getMessage());
			}
 
		}
 
 
 
	/**
         * This method initializes jTable
         * 
         * @return javax.swing.JTable
         */
	private JTable getJTable() {
 
		//Vector cl = new Vector();
		cl.addElement("Column AFC");
		cl.addElement("Column Country");
		cl.addElement("Column Year");
 
		Vector v1 = new Vector(3);
		v1.addElement("1111111111");
		v1.addElement("2222222222");
		v1.addElement("3333333333");
 
		Vector v2= new Vector(3);
		v2.addElement("44444444");
		v2.addElement("55555555");
		v2.addElement("6666666666");
 
		columnData.addElement(v1);
		columnData.addElement(v2);
 
		jTable = new JTable();
		jTable = new JTable(columnData,cl);
		if(jTable == null) {
			jTable = new JTable();
		}
 
		return jTable;
	}
	/**
         * This method initializes jScrollPane
         */
	private JScrollPane getJScrollPane() {
		if(jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(90, 56, 338, 94);
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}
 
	public void getDataList() {
 
				Vector v1 = new Vector(3);
				v1.addElement("aaaaa");
				v1.addElement("bbbbb");
				v1.addElement("cccccc");
 
				Vector v2= new Vector(3);
				v2.addElement("aaaaa");
				v2.addElement("bbbbb");
				v2.addElement("cccccc");
 
				Vector v3= new Vector(3);
				v3.addElement("aaaaa");
				v3.addElement("bbbbb");
				v3.addElement("cccccc");
 
				columnData.addElement(v1);
				columnData.addElement(v2);
				columnData.addElement(v3);
 
	}
 
}  //  @jve:visual-info  decl-index=0 visual-constraint="15,4"