Bonjour à tous,
J'ai une classe fenetre qui contient un comboBox qui me permet de choisir la langue de travail ( français, anglais, ou allemand), selon la valeur de la langue choisie s'affiche dans un Jtable un ensemble de propriétés extraites de ma base mySQl, j'ai chargé ses propriétés à partir de la base dans une ArrayList listBoxCategoriedans la méthode getListBoxCatégorie
Voici le code de la comboBox et du chargement du contenu de l'ArrayList dans la table table_2
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 public static ArrayList <String> getListBoxCategorie(){ ArrayList <String >listBoxCategorie = new ArrayList<String>(); if (fenetre.equals("Anglais" )){ String query= "SELECT * FROM categ_donnees where Nom_categ not like (\"Traduction en anglais\")"; Connect objcon= new Connect(); ResultSet result= objcon.connecter(query); try{ while(result.next()){ listBoxCategorie.add(result.getString("Nom_categ")); } } catch(Exception e){ javax.swing.JOptionPane.showMessageDialog(null, e.getMessage(), "Erreur", 2); } } else { if ((fenetre.getLangue()).equals("Allemand")){ String query= "SELECT * FROM categ_donnees where Nom_categ not like (\"Traduction en allemand\")"; Connect objcon= new Connect(); ResultSet result= objcon.connecter(query); try{ while(result.next()){ listBoxCategorie.add(result.getString("Nom_categ")); ; } } catch(Exception e){ javax.swing.JOptionPane.showMessageDialog(null, e.getMessage(), "Erreur", 2); } } else { if ((fenetre.getLangue()).equals("Fran\u00E7ais")){ String query= "SELECT * FROM categ_donnees where Nom_categ not like (\"Traduction en fran\u00E7ais\")"; Connect objcon= new Connect(); ResultSet result= objcon.connecter(query); try{ while(result.next()){ listBoxCategorie.add(result.getString("Nom_categ")); } } catch(Exception e){ javax.swing.JOptionPane.showMessageDialog(null, e.getMessage(), "Erreur", 2); } } } } return listBoxCategorie; }
Mon problème est que quand je change la langue à partir du comboxBox les valeurs ne changent pas, sauf les premieres valeurs du premier item (français) sont affichées. Pouvez vous m'aidez???
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 public class fenetre extends JFrame { private JPanel contentPane; public static String langue; private JTable table_2; public fenetre(){ final static JComboBox comboBox = new JComboBox(); comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { langue =(String)comboBox.getSelectedItem(); } }); comboBox.setModel(new DefaultComboBoxModel(new String[] {"Fran\u00E7ais","Anglais", "Allemand"})); langue =(String)comboBox.getSelectedItem(); comboBox.setFont(new Font("Calibri", Font.PLAIN, 17)); comboBox.setBounds(361, 97, 154, 23); contentPane.add(comboBox); for (int i = 0; i < listBoxCategorie.size(); i++) { String str = (String) listBoxCategorie.get(i); table_2.setValueAt(str,i, 0); } } public static String getLangue(){ return langue; } }
Merci d'avance
Partager